#include<stdio.h>
void ShellSort(int*a,int size)
{
int gap = size;
int i,end,temp;//end是从后往前进行比较时指向的被比较者
while(gap>1)
{
gap = gap/3+1;
for(i = 0;i<size-gap;i++)//i指到size-gap-1时第一次遍历结束 ,开始下一次
{
end = i;
temp = a[end+gap];
while(end>=0)
{
if(a[end]>temp)
{
a[end+gap] = a[end];
end-=gap;
}
else
break;
}
a[end+gap] = temp;
}
}
}
int main()
{
int a[8] ={ 12,65,14,3,98,4,7,44};
int size = 8;
ShellSort(a,size);
for(int i = 0;i<8;i++)
printf("%d ",a[i]);
return 0;
}