#include <stdio.h>
#include <stdlib.h>
void InsertionSort(int a[], int n)
{
int in, out, temp;
for (out = 1; out < n; out++)
{
temp = a[out];
in = out;
while (a[in-1]>=temp && in>0)
{
a[in] = a[in-1];
in--;
}
a[in] = temp;
}
return;
}
void main()
{
int i;
int a[10] = { 2, 4, 6, 8, 0, 1, 3, 5, 7, 9 };
InsertionSort(a, 10);
for (i = 0; i < 10;i++)
{
printf("%d\n", a[i]);
}
system("pause");
return;
}
#include <stdlib.h>
void InsertionSort(int a[], int n)
{
int in, out, temp;
for (out = 1; out < n; out++)
{
temp = a[out];
in = out;
while (a[in-1]>=temp && in>0)
{
a[in] = a[in-1];
in--;
}
a[in] = temp;
}
return;
}
void main()
{
int i;
int a[10] = { 2, 4, 6, 8, 0, 1, 3, 5, 7, 9 };
InsertionSort(a, 10);
for (i = 0; i < 10;i++)
{
printf("%d\n", a[i]);
}
system("pause");
return;
}