A talk C Chestnut bar (28th time: C-language example-hill sort)

Source: Internet
Author: User


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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.