Hill Sorting Algorithm
/* Date: 2014.12.14
Hill sorting idea: Based on the insert sorting idea.
Process: 1). Divide an array with n elements into n/2 pairs, 1st data pairs, and (n/2 + 1) data pairs;
2). A loop is used to sort the order of each sequence;
3). sort by n/4 pairs;
4) Repeat operations. The sorting of the entire sequence is completed when the number of sequences is reduced to one.
Time Complexity: Worst (O (ns) 1 Space complexity: O (1 ).
It is an unstable sorting algorithm.
*/
Void ShellSort (int * arr, int len)
{
Int I, j, k;
Int r, temp;
Int t = 0;
For (r = len/2; r> = 1; r/= 2)
{
For (I = r; I <len; I ++)
{
Temp = arr [I];
J = I-r;
While (j> = 0 & temp <arr [j])
{
Arr [j + r] = arr [j];
J-= r;
}
Arr [j + r] = temp;
}
T ++;
Printf ("the sorting result of step % d is:", t );
For (k = 0; k <len; k ++)
{
Printf ("% d", arr [k]);
}
Printf ("\ n ");
}
}