Below is a C implementation of the Shellsort:
void insertionsort (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)
swapi (A[j], A[j-incr]);
}
void shellsort (int *array, int n) {
int i, j;
for (i = (n/2); i > 1; i /= 2)
for (j = 0; j < i; j++)
insertionsort(\&array[j], n-j, i);
insertionsort(array, n, 1);
}
|