@Test public void testHeapSort() { int[] origin = SortUtil.initArray(arraySize); SortUtil.print(origin); long start = System.currentTimeMillis(); SortUtil.heapSort(origin); long interval = System.currentTimeMillis() - start; System.out.println("call heapSort, time cost is: " + interval + "ms"); SortUtil.print(origin); }
public static void heapSort(int[] data) { if (data == null || data.length < 2) { return; } for (int i = (data.length - 2) / 2; i >= 0; i--) { adjustHeap(data, i, data.length); } for (int j = data.length - 1; j > 0; j--) { swap(data, 0, j); adjustHeap(data, 0, j); } }
SortUtil { public static void heapSort(int[] data) { if (data == null || data.length < 2) { return; } for (int i = (data.length - 2) / 2; i >= 0; i--) { adjustHeap(data, i, data.length); } for (int j = data.length - 1; j > 0; j--) { swap(data, 0, j); adjustHeap(data, 0, j); } } }
SortUtil { public static void heapSort(int[] data) { if (data == null || data.length < 2) { return; } for (int i = (data.length - 2) / 2; i >= 0; i--) { adjustHeap(data, i, data.length); } for (int j = data.length - 1; j > 0; j--) { swap(data, 0, j); adjustHeap(data, 0, j); } }  }
SortUtil { public static void heapSort(int[] data) { if (data == null || data.length < 2) { return; } for (int i = (data.length - 2) / 2; i >= 0; i--) { adjustHeap(data, i, data.length); } for (int j = data.length - 1; j > 0; j--) { swap(data, 0, j); adjustHeap(data, 0, j); } }  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 heapSort(int[] data) { if (data == null || data.length < 2) { return; } for (int i = (data.length - 2) / 2; i >= 0; i--) { adjustHeap(data, i, data.length); } for (int j = data.length - 1; j > 0; j--) { swap(data, 0, j); adjustHeap(data, 0, j); } }  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);  }