4.7 Hill (Shell) sorting method

Source: Internet
Author: User

4-7 shellsort.c

1#include <stdio.h>2#include"4-1 createdata.c"    //function to generate random numbers3 #defineArraylen 10//number of data elements that need to be sorted4 voidShellsort (intA[],intN//Hill Sort5 {6     intd,i,j,x;7d=n/2;8      while(d>=1)//loop to increment to end 1 o'clock9     {Ten          for(i=d;i<n;i++) One         { AX=a[i];//gets the next data in the sequence -j=i-d;//ordinal of the previous data in a sequence -              while(j>=0&& a[j]>x)//The next number is greater than the previous number the             { -A[J+D]=A[J];//move the latter number forward -j=j-d;//Modify the ordinal to continue the forward comparison -             } +A[j+d]=x;//Save Data -         } +D/=2;//Decrease Increment A     } at } - intMain () - { -     intI,a[arraylen];//Defining Arrays -      for(i=0; i<arraylen;i++)//Empty Array -a[i]=0; in     if(! Createdata (A,arraylen,1, -))//determine if generating random numbers is successful -     { toprintf"generate random number unsuccessful!\n"); + getch (); -         return 1; the     } *printf"Original data:");//random number generated by output $      for(i=0; i<arraylen;i++)Panax Notoginsengprintf"%d", A[i]); -printf"\ n"); theShellsort (A,arraylen);//Call the hill sort function +printf"after sorting:");  A      for(i=0; i<arraylen;i++)//results after sorting the output theprintf"%d", A[i]); +printf"\ n"); - getch (); $     return 0;  $}

4.7 Hill (Shell) sorting method

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.