#include <stdio.h>voidsort(intarray[], intstart, intend);
voidshow(intnum[], intlength);
intmain(void)
{
intarray[] = {5, 2, 4, 7, 1, 3, 2, 6},len=8;
printf("排序前:\n");
show(array, len);
sort(array, 0, len-1);
printf("排序后:\n");
show(array, len);
}
voidshow(intnum[], intlength)
{
for (inti=0; i<length; i++)
{
printf("%3d", num[i]);
}
printf("\n");
}
voidsort(intarray[], intstart, intend)
{
if (start==end)
{
return;
}
intlstart=start, lend= (start+end) /2, rstart=lend+1, rend=end;
sort(array, lstart, lend);
sort(array, rstart, rend);
for (inti=rstart; i<=rend; i++)
{
intj=i-1, tmp=array[i];
while (array[j] >tmp&&j>=0)
{
array[j+1] =array[j];
j--;
}
array[j+1] =tmp;
}
}