@Test public void testShellSort() throws Exception { int[] origin = SortUtil.initArray(arraySize); SortUtil.print(origin); long start = System.currentTimeMillis(); SortUtil.shellSort(origin); long interval = System.currentTimeMillis() - start; System.out.println("call shellSort, time cost is: " + interval + "ms"); SortUtil.print(origin); }
public static void shellSort(int[] data) { if (data == null || data.length < 2) { return; } int d = data.length / 2; while (d >= 1) { for (int k = 0; k < d; k++) { for (int i = k + d; i < data.length; i += d) { int temp = data[i]; int j = i - d; while (j >= k && data[j] > temp) { data[j + d] = data[j]; j -= d; } data[j + d] = temp; } } d = d / 2; } }
SortUtil { public static void shellSort(int[] data) { if (data == null || data.length < 2) { return; } int d = data.length / 2; while (d >= 1) { for (int k = 0; k < d; k++) { for (int i = k + d; i < data.length; i += d) { int temp = data[i]; int j = i - d; while (j >= k && data[j] > temp) { data[j + d] = data[j]; j -= d; } data[j + d] = temp; } } d = d / 2; } } }
SortUtil { public static void shellSort(int[] data) { if (data == null || data.length < 2) { return; } int d = data.length / 2; while (d >= 1) { for (int k = 0; k < d; k++) { for (int i = k + d; i < data.length; i += d) { int temp = data[i]; int j = i - d; while (j >= k && data[j] > temp) { data[j + d] = data[j]; j -= d; } data[j + d] = temp; } } d = d / 2; } }  }
SortUtil { public static void shellSort(int[] data) { if (data == null || data.length < 2) { return; } int d = data.length / 2; while (d >= 1) { for (int k = 0; k < d; k++) { for (int i = k + d; i < data.length; i += d) { int temp = data[i]; int j = i - d; while (j >= k && data[j] > temp) { data[j + d] = data[j]; j -= d; } data[j + d] = temp; } } d = d / 2; } }  static void setIsPrint(boolean isPrint); static int[] initArray(final int n); static void print(int[] data); static void selectSort(int[] data); static void insertSort(int[] data); static void binaryInsertionSort(int[] data); static void shellSort(int[] data); static void bubbleSort(int[] data); static void quickSort(int[] data); static void mergeSort(int[] data); static void heapSort(int[] data); static void radixSort(int[] data, int maxBit); static int getDigitBit(int data); static int getFigure(int data, int n); List<SortObject<Double>> multiSort(int num, boolean ascend); }
SortUtil { public static void shellSort(int[] data) { if (data == null || data.length < 2) { return; } int d = data.length / 2; while (d >= 1) { for (int k = 0; k < d; k++) { for (int i = k + d; i < data.length; i += d) { int temp = data[i]; int j = i - d; while (j >= k && data[j] > temp) { data[j + d] = data[j]; j -= d; } data[j + d] = temp; } } d = d / 2; } }  static void setIsPrint(boolean isPrint); static int[] initArray(final int n); static void print(int[] data); static void selectSort(int[] data); static void insertSort(int[] data); static void binaryInsertionSort(int[] data); static void shellSort(int[] data); static void bubbleSort(int[] data); static void quickSort(int[] data); static void mergeSort(int[] data); static void heapSort(int[] data); static void radixSort(int[] data, int maxBit); static int getDigitBit(int data); static int getFigure(int data, int n); List<SortObject<Double>> multiSort(int num, boolean ascend);  }