Packagebackup class; Public classHill Inline Sort { Public Static voidMain (string[] args) {int[] A =New int[] {9, 8, 7, 6, 5, 4, 3, 2, 1, 10 }; Print (a); Shellsort (a); Print (a); } Public Static voidShellsort (int[] a) {intD = 3;//Incremental intGap = 1;//spacing//calculates the maximum gap value while(Gap <= A.length/d) {gap= Gap * D + 1; } //inter-group loops while(Gap > 0) { //a group of loops within for(inti = gap; i < a.length; i + =Gap) { if(A[i-gap] >A[i]) { intTMP =A[i]; intj = i-Gap; while(J >= 0 && a[j] > tmp) {//started moving.A[j + gap] =A[j]; J-=Gap; } a[j+ Gap] =tmp; Print (a); } } //calculate the next gap value, start the next set of sorting, the next set of gap reductionGap = (gap-1)/D; } } Public Static voidPrintint[] a) { for(inti = 0; i < a.length; i++) {System.out.print (A[i]+ "\ T"); } System.out.println (); }}
Hill sort Java Code