#include
#include
int shell_sort(int array[], int size)
{
int temp, step, i, flag = 1;
step = size / 2;
do
{
flag = 0;
for (i = 0; i + step < size; i++)
{
if (array[i] > array[i + step])
{
temp = array[i];
array[i] = array[i + step];
array[i + step] = temp;
flag = 1;
}
}
if ((step == 1) && (flag ==1))
continue;
step /= 2;
}while((flag == 1) || (step > 0));
}
int main(void)
{
int values[30], i;
for (i = 0; i < 30; i++)
{
values[i] = rand()%100;
printf("%d ", values[i]);
}
shell_sort(values, 30);
printf("\n");
for (i = 0; i < 30; i++)
printf("%d ",values[i]);
return 0;
}
阅读(495) | 评论(0) | 转发(0) |