Data Structure --- implement Hill sorting in C Language
// Shell Sort // Yang Xin # include
# Include
Void ShellSort (int a [], int length) {int increment; int I, j; int temp; for (increment = length/2; increment> 0; increment/= 2) // used to control the step size, and finally decreases to 1 {// I is arranged starting from step. It should be the first element to be inserted for sorting. // you can not move it first, sort for (I = increment; I <length; I ++) {temp = a [I]; for (j = I-increment; j> = 0 & temp <a [j]; j-= increment) {a [j + increment] = a [j];} a [j + increment] = temp; // fill in the first position }}} int main () {printf (==================== Hill sort ========================); int I, j; int a [] = {5, 18,151,138,160, 63,174,169, 79,200}; printf (the sequence to be sorted is:); for (I = 0; I <10; I ++) {printf (% d, a [I]);} ShellSort (a, 10); printf (the sorted sequence is:); for (j = 0; j <10; j ++) {printf (% d, a [j]);} printf (); return 0 ;}