Hill Sorting Algorithm

Source: Internet
Author: User

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

}



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.