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