Added example 2-4. Program compares strings.
[C-Programming-Examples.git] / shell_sort.c
blobff8db48ebf4eaa81187a951820e6370abf3b7198
1 /*
3 Invented in 1959 by D. L. Shell
5 Sorts an array of integers
7 From Page 60 & 61.
9 */
11 #include <stdio.h>
13 void shellsort(int v[], int n)
15 int gap, i, j, temp;
17 for(gap = n/2; gap > 0; gap /=2)
19 for(i = gap; i < n; i++)
21 for(j = i - gap; j >=0 && v[j]>v[j+gap]; j-=gap)
23 temp = v[j];
24 v[j] = v[j+gap];
25 v[j+gap] = temp;
31 int main()
33 int data[10] = { 9, 12, 54, 90, 0, 100, 65, 32, 54, 81};
34 int i;
36 for(i = 0; i < 10; ++i) { printf("%d\n", data[i]); }
38 shellsort(data, 10);
40 for(i = 0; i < 10; ++i) { printf("%d\n", data[i]); }
42 return 0;