PackageCom.edu.hpu.sort.insert.shell;Importjava.util.Arrays;ImportCom.edu.hpu.sort.Sort; Public classShellsortextendsSort {@Override Public int[] Dosort (int[] arr) { intLen =arr.length; //all step probabilities (for the first half of the group leader, the next half for the last time) for(intGap = LEN/2; Gap > 0; Gap/= 2) { //Insert sort all elements in step for(intw = 0; W < Gap; w++){ //insertion sort with step gap//Control Insert Sort /** for (int i = p + 1; i < R; i++) {* int key = Arr[i]; * Int j = i-1; * while (J >= 0 && Arr[j] > key) {* Arr[j + 1] = Arr[j]; * j--; *} * arr[j + 1] = key; * } */ for(inti = Gap + W; i < Len; i + =Gap) { //Insert Sort intKey =Arr[i]; intj = i-Gap; while(J >= 0 && Arr[j] >key) {Arr[j+ Gap] =Arr[j]; J-=Gap; } arr[j+ Gap] =key; }} System.out.println (Arrays.tostring (arr)); } returnarr; } Public Static voidMain (string[] args) {sort sort=NewShellsort (); Sort.printorder (New int[] {100, 201, 999, 4, 1, 3, 2, 16, 9, 100, 194, 8, 7, 0, 90 }); }}
Java implementation of Shell sequencing