@Test public void test() { Shell.Sort(CommonData.OUT_OF_ORDER_ARRAY); for (int a : CommonData.OUT_OF_ORDER_ARRAY) { System.out.println(a); } }
public static void Sort(int[] array) { int d = array.length; while (true) { d = d / 2; for (int i = 0; i < d; i++) { for (int j = i + d; j < array.length; j += d) { int temp = array[j]; int k = j-d ; while (k >= 0 && temp < array[k]) { array[k+d]=array[k]; k-=d; } array[k+d]=temp; } } if (d==1) break; } }
Shell { public static void Sort(int[] array) { int d = array.length; while (true) { d = d / 2; for (int i = 0; i < d; i++) { for (int j = i + d; j < array.length; j += d) { int temp = array[j]; int k = j-d ; while (k >= 0 && temp < array[k]) { array[k+d]=array[k]; k-=d; } array[k+d]=temp; } } if (d==1) break; } } }
Shell { public static void Sort(int[] array) { int d = array.length; while (true) { d = d / 2; for (int i = 0; i < d; i++) { for (int j = i + d; j < array.length; j += d) { int temp = array[j]; int k = j-d ; while (k >= 0 && temp < array[k]) { array[k+d]=array[k]; k-=d; } array[k+d]=temp; } } if (d==1) break; } }  }
Shell { public static void Sort(int[] array) { int d = array.length; while (true) { d = d / 2; for (int i = 0; i < d; i++) { for (int j = i + d; j < array.length; j += d) { int temp = array[j]; int k = j-d ; while (k >= 0 && temp < array[k]) { array[k+d]=array[k]; k-=d; } array[k+d]=temp; } } if (d==1) break; } }  static void Sort(int[] array); }
Shell { public static void Sort(int[] array) { int d = array.length; while (true) { d = d / 2; for (int i = 0; i < d; i++) { for (int j = i + d; j < array.length; j += d) { int temp = array[j]; int k = j-d ; while (k >= 0 && temp < array[k]) { array[k+d]=array[k]; k-=d; } array[k+d]=temp; } } if (d==1) break; } }  static void Sort(int[] array);  }