# Include <stdio. h>
/* Sort by hill
Basic Idea: Hill sorting, also known as downgrading incremental sorting, optimizes simple insertion sorting. (External group gap, sorting of group insertion !!)
Features: an unstable sorting
*/
Void shellsort (INT array [], int Len ){
Int I, J;
Int gap; // gap
Int temp;
For (Gap = Len/2; Gap> 0; Gap = gap/2) {// The core is to compare array [J + Gap] With array [J] Until Gap = 1
For (I = gap; I <Len; I ++) {// I: Gap ~ <Len (I ++) 4, 3, 2, 1...
Temp = array [I];
For (j = I-gap; j> = 0; j-= gap) {// J: I-gap ~ > = 0 (j = J-gap)
If (temp <array [J]) {
Array [J + Gap] = array [J]; // If the element to be inserted <the previous sequence, the elements are removed.
}
Else
Break;
}
Array [J + Gap] = temp; // fill in the elements to be inserted.
}
}
}
Int main (INT argc, const char * argv [])
{
Int I = 0;
Int A [] = };
Int Len = sizeof (a)/sizeof (A [0]);
// Sort by hill
Shellsort (A, Len );
For (I = 0; I <Len; I ++ ){
Printf ("% d", a [I]);
}
Printf ("\ n ");
Return0;
}
Deep introduction to the sort algorithm-hill sort