#include<stdio.h>
void Shellsort(int n[], int size)
{
int i,gap,temp,end;
gap = size;
while (gap > 1)
{
gap = gap / 3 + 1;
for (i = 0; i < size - gap; i++)
{
if (n[i] > n[gap + i])
{
temp = n[i];
n[i] = n[gap + i];
n[gap + i] = temp;
}
}
}
if (gap == 1)
{
for (i = 0; i < size - 1; i++)
{
end = i;
temp = n[end + 1];
while (end >= 0)
{
if (temp < n[end])
{
n[end + 1] = n[end];
}
else
{
break;
}
end--;
}
n[end+1] = temp;
}
}
}
int main()
{
int i,n[8] = { 5,3,2,8,6,4,7,1 };
Shellsort(n, 8);
for (i = 0; i < 8; i++)
{
printf("%d ", n[i]);
}
return 0;
return 0;
}