Hill Sort algorithm

Source: Internet
Author: User

/* date:2014.12.14
Hill sort ideas: Based on the idea of insertion sorting.
Process: 1). The array of n elements is divided into n/2 pairs, the 1th data and the first (N/2 + 1) data are pairs, paired in turn;
2). A cycle allows each sequence to be sorted in order;
3). Again divided into N/4 to be sorted;
4). Repeat, the order of the entire sequence is completed by reducing the logarithm of the sequence to 1.
Time complexity: Worst (O (NS) 1<s<2), average O (Nlogn).
Space complexity: O (1).
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 result of step%d sorting is:", t);
for (k = 0;k < Len;k + +)
{
printf ("%d", arr[k]);
}
printf ("\ n");
}

}



Hill Sort algorithm

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.