MCPcopy Create free account
hub / github.com/PrajaktaSathe/Java / shellsort

Method shellsort

Programs/ShellSort.java:15–38  ·  view source on GitHub ↗
(int[] array)

Source from the content-addressed store, hash-verified

13 }
14
15 private static int[] shellsort(int[] array) {
16
17 // first part uses the Knuth's interval sequence
18 int h = 1;
19 while (h <= array.length / 3) {
20 h = 3 * h + 1;
21 }
22
23 while (h > 0) {
24
25 for (int i = 0; i < array.length; i++) {
26
27 int temp = array[i];
28 int j;
29
30 for (j = i; j > h - 1 && array[j - h] >= temp; j = j - h) {
31 array[j] = array[j - h];
32 }
33 array[j] = temp;
34 }
35 h = (h - 1) / 3;
36 }
37 return array;
38 }
39
40}

Callers 1

mainMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected