@Test public void sort() { Integer[] sortIntegerArray = { 1, 2, 5, 4, 3 }; Integer[] resultArray = { 1, 2, 3, 4, 5 }; ShellSort.sort(sortIntegerArray); Assert.assertArrayEquals(sortIntegerArray, resultArray); }
public static void sort(Comparable[] a) { int N = a.length; int h = 1; while (h < N / 3) h = h * 3 + 1; while (h >= 1) { for (int i = h; i < N; i++) { for (int j = i; j >= h && Utils.less(a[j], a[j - h]); j -= h) Utils.exch(a, j, j - h); } h = h / 3; } }
ShellSort { public static void sort(Comparable[] a) { int N = a.length; int h = 1; while (h < N / 3) h = h * 3 + 1; while (h >= 1) { for (int i = h; i < N; i++) { for (int j = i; j >= h && Utils.less(a[j], a[j - h]); j -= h) Utils.exch(a, j, j - h); } h = h / 3; } } }
ShellSort { public static void sort(Comparable[] a) { int N = a.length; int h = 1; while (h < N / 3) h = h * 3 + 1; while (h >= 1) { for (int i = h; i < N; i++) { for (int j = i; j >= h && Utils.less(a[j], a[j - h]); j -= h) Utils.exch(a, j, j - h); } h = h / 3; } }  }
ShellSort { public static void sort(Comparable[] a) { int N = a.length; int h = 1; while (h < N / 3) h = h * 3 + 1; while (h >= 1) { for (int i = h; i < N; i++) { for (int j = i; j >= h && Utils.less(a[j], a[j - h]); j -= h) Utils.exch(a, j, j - h); } h = h / 3; } }  static void sort(Comparable[] a); static void main(String[] args); }
ShellSort { public static void sort(Comparable[] a) { int N = a.length; int h = 1; while (h < N / 3) h = h * 3 + 1; while (h >= 1) { for (int i = h; i < N; i++) { for (int j = i; j >= h && Utils.less(a[j], a[j - h]); j -= h) Utils.exch(a, j, j - h); } h = h / 3; } }  static void sort(Comparable[] a); static void main(String[] args);  }