插入排序(递归)
#include <stdio.h>
#include <stdlib.h>
void fun(int *a, int num)
{
int i = num - 1;
int key = a[num];
while (i>0 && a[i]>key)
{
a[i + 1] = a[i];
i--;
}
a[i + 1] = key;
}
void Sort(int *a, int num)
{
if (num>1){
Sort(a, num - 1);
fun(a, num);
}
}
int main()
{
int a[10] = { 3, 41, 52, 26, 38, 57, 9, 49 };
Sort(a, 7);
int i;
for (i = 0; i<8; i++)
{
printf("%d ", a[i]);
}
system("pause");
return 0;
}