Deep introduction to the sort algorithm-hill sort

Source: Internet
Author: User

# 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.





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 ");



Deep introduction to the sort algorithm-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: 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.