#include <stdio.h>
void swap(int a[], int i, int j)
{
int t = a[i];
a[i] = a[j];
a[j] = t;
}
void selsort(int a[], int n, int incr)
{
int i, j;
for (i = incr; i < n; i += incr)
for (j = i; (j >= incr)
&& (a[j] < a[j-incr]); j -= incr)
swap(a, j, j-incr);
}
void shellsort(int a[], int n)
{
int i, j;
for (i = n / 2; i > 2; i /= 2)
for (j = 0; j < i; j++)
selsort(&a[j], n - j, i);
selsort(a, n, 1);
}
int main()
{
int i;
int a[10] = {2, 1, 9, 0, 8, 3, 7, 5, 6, 4};
shellsort(a, 10);
for (i = 0; i < 10 ; i++)
printf("%d ", a[i]);
printf("\n");
return 0;
}
不负相思意