6 typedef int T; /* type of item to be sorted */
7 typedef int tblIndex; /* type of subscript */
9 #define compGT(a,b) (a > b)
11 void shellSort(T *a, tblIndex lb, tblIndex ub) {
16 static const unsigned int h[] = {
17 1, 5, 19, 41, 109, 209, 505, 929, 2161, 3905, 8929,
18 16001, 36289, 64769, 146305, 260609, 587521, 1045505,
19 2354689, 4188161, 9427969, 16764929, 37730305, 67084289,
20 150958081, 268386305, 603906049, 1073643521, 2415771649U
23 /* find t such that 3*h[t] >= n */
25 for (t = 0; 3*h[t] < n; t++);
27 /* start with h[t-1] */
33 /* sort-by-insertion in increments of h */
35 for (i = lb + ht; i <= ub; i++) {
37 for (j = i-ht; j >= lb && compGT(a[j], tmp); j -= ht)
44 void fill(T *a, tblIndex lb, tblIndex ub) {
47 for (i = lb; i <= ub; i++) a[i] = rand();
50 int main(int argc, char *argv[]) {
51 tblIndex maxnum, lb, ub;
62 maxnum = atoi(argv[1]);
63 lb = 0; ub = maxnum - 1;
64 if ((a = malloc(maxnum * sizeof(T))) == 0) {
65 fprintf (stderr, "insufficient memory (a)\n");