The interchange of nonadjacent elements is sorted locally on the array, and the ordered arrays are sorted by an insert sort
Read the program to write casually (in order to understand more clearly on the paper to write a run process)
Although this code is written, this program should theoretically be no problem, but I have not run it yet, each run will appear the following situation
(Hope to have a better understanding of it later.)
Packagesort20171111;ImportJava.util.Scanner; Public classShell { Public Static voidMain (string[] args) {//TODO auto-generated Method Stub int[]a =New int[5]; intN; Scanner in=NewScanner (system.in); N=In.nextint (); for(inti = 0; I < n; i++) {A[i]=In.nextint (); } //Hill Sort intH = 1; while(H < N/3) {h= h * 3 + 1; } while(H >= 1) { for(inti = h; I < n; i++) { for(intj = i; J >= H; j = J-h) {if(A[j] < a[j-h]) {inttemp; Temp=A[j]; A[J]= A[j-h]; A[j-H] =temp; }} H= H/3; } } for(inti = 0; I < n; i++) {System.out.println (a[i]); } }}
Hill Sort (JAVA)