#include<string.h>
#include<stdlib.h>
#include<stdio.h>
void Print(int *array,int size);
void ShellSort(int *array, int size);
void Print(int *array, int size)
{
int i = 0;
for (i = 0; i < size; i++)
{
printf("%d ", array[i]);
}
printf("\n");
}
void ShellSort(int *array, int size)
{
int gap = 3;
int i = 0;
int j = 1;
int pos = 0;
int k = 0;
while (gap)
{
for (i = 0; i < size; i++)
{
k = array[i + gap];
if (i + gap >= size)
{
break;
}
pos = i;
while (k < array[pos] && pos>=0)
{
array[pos + gap] = array[pos];
pos = pos - gap;
}
array[pos + gap] = k;
}
printf("第%d次排序后:",j++);
Print(array, size);
gap--;
}
}