Ladies and gentlemen, crossing, the last time we were talking about inserting sort examples, this time we say the example is: Hill sort. Gossip Hugh
The words return to a positive turn. Let's talk C chestnuts together!
Hill sort is an improvement on the insertion sort, the principle of the Hill sort : First divide the container into several sub-containers, then separate the
Insert sort, and once the sub-containers are all sorted, insert a sort once for all the elements.
steps to implement the Hill sort :
1. Select an increment, the size of the increment can be defined by itself, its size is between 1 and the container length;
2. Take the container head to the increment position of the element as the starting point, from the starting point to the container tail loop through the container;
3. In step 2 of the traversal process, select a current position of the element, and then select the position of the increment from the current position of the element to compare;
4. If the two elements in step 3 conform to the collation, go back to step 2;
5. If the two elements in step 3 do not conform to the collation, then make a selection sort;
6. Reduce the increment of the value, how much to reduce, you can define, I reduced in the program 1;
7. Repeat step 2 through step 6 until the increment value equals.
Crossing, the text does not write code, the detailed code put in my resources, you can click here to download the use. Sort in Hill
The insertion sort is used, but it is more efficient than the insert sort, which is all the credit for the increment.
You crossing, here's an example of the sort of hill we're talking about here. I want to know what the following example, and listen to tell.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
A talk C Chestnut bar (28th time: C-language example-hill sort)