| Copyright Notice: This article for Bo Master original article, without Bo Master permission not reproduced.
Hill sort, is a narrowing incremental sort. It is sorted according to the step size, different steps may produce different sequences, but their final result is the same, the official theory of hill sort is difficult to understand, this is explained by unofficial explanation.
Principle:
>1. Adding a sequence of n nodes, assuming the step I of the hill sort, then our first step is to set the N nodes, every I-seat, as a group, as shown below (step I to take good):
[N1, N1+i]
[N2, Ni+2]
[...........]
[NX, NN]
>2. Then each group of 22 comparisons, such as N1 and N1+i comparisons, select the appropriate (appropriate refers to the sort of ascending and descending relationship) data in front. If N1+i < N1, and in ascending order, then the first set of sorted sequence is [N1+i, N1], and so on, and so on, make up the order of the X group. Suppose the following is a well-ordered sequence.
[N1+i, N1]
[N2, Ni+2]
[N3, Ni+3]
[Ni+4, N4]
[...........]
[NX, NN]
>3. Finally, the vertical sequence will be followed by all the nodes, which is the result of the first trip of the hill sort, according to >2. The result is: N1+i, N2, N3, Ni+4, ...., NX, N1, ni+2, ni+3, N4, .... Nn
>4. Then the step I minus 1, repeat the above operation until i=0, end.
Example: Take the (5,6,1,8,4,9) sequence as an example to demonstrate the results of the first trip sort
Hill sort (shell) theory---does not contain source code