#include
void sort(int array[], int start, int end);
void show(int num[], int length);
int main(void)
{
int array[] = {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);
}
void show(int num[], int length)
{
for (int i = 0; i < length; i++)
{
printf("%3d", num[i]);
}
printf("\n");
}
void sort(int array[], int start, int end)
{
if (start == end)
{
return;
}
int lstart = start, lend = (start + end) / 2, rstart = lend + 1, rend = end;
sort(array, lstart, lend);
sort(array, rstart, rend);
for (int i = rstart; i <= rend; i++)
{
int j = i - 1, tmp = array[i];
while (array[j] > tmp && j >= 0)
{
array[j + 1] = array[j];
j--;
}
array[j + 1] = tmp;
}
}