The Hill sort (Shell sort) is a sort of insertion. is an improvement on the direct insertion sorting algorithm. This method is also known as narrowing the incremental sort, because of the DL. The shell was named after it was introduced in 1959.
Basic idea: The algorithm will sort the group of numbers according to an increment D (n/2,n to the number of numbers to be sorted) into several groups, each group of records of the subscript difference D. Direct insert sorting of all elements in each group, followed by a smaller increment (D/2) to group it, followed by a direct insert sort in each group. When the increment is reduced to 1 o'clock, the sort is completed after the direct insert sort.
Code implementation:
1 Packagesort;2 3 Public classShellsort {4 Public Static voidMain (String[]args) {5 int[]array={49,38,65,97,76,13,27,49,55,4};6 DoubleLength=Array.Length;7 8 intTemp=0;9 while(true){//use D to determine the number of outermost loopsTenLength=math.ceil (LENGTH/2); One intD= (int) (length); A for(intx=0; x<d;x++){ - for(inti=x+d;i<array.length;i+=d) { -temp=Array[i]; the intj=i-D; - for(; j>=0&&temp<array[j];j-=d)//Insert Sort -array[j+d]=Array[j]; -array[j+d]=temp; + - } + A } at - if(d==1) Break; - - } - for(inti=0;i<array.length;i++) -System.out.print (array[i]+ ""); in } - to +}
Starting from the sort of Java (2)--Hill sort