@Test public void test() { Heap.Sort(CommonData.OUT_OF_ORDER_ARRAY); for (int a : CommonData.OUT_OF_ORDER_ARRAY) { System.out.println(a); } }
public static void Sort(int[] array) { if (array == null || array.length <= 1) { return; } int half = (array.length-1) / 2; for (int i = half; i >= 0; i--) { maxHeap(array, array.length, i); } for (int i = array.length - 1; i >= 1; i--) { int temp = array[0]; array[0]=array[i]; array[i]=temp; maxHeap(array, i, 0); } }
Heap { public static void Sort(int[] array) { if (array == null || array.length <= 1) { return; } int half = (array.length-1) / 2; for (int i = half; i >= 0; i--) { maxHeap(array, array.length, i); } for (int i = array.length - 1; i >= 1; i--) { int temp = array[0]; array[0]=array[i]; array[i]=temp; maxHeap(array, i, 0); } } }
Heap { public static void Sort(int[] array) { if (array == null || array.length <= 1) { return; } int half = (array.length-1) / 2; for (int i = half; i >= 0; i--) { maxHeap(array, array.length, i); } for (int i = array.length - 1; i >= 1; i--) { int temp = array[0]; array[0]=array[i]; array[i]=temp; maxHeap(array, i, 0); } }  }
Heap { public static void Sort(int[] array) { if (array == null || array.length <= 1) { return; } int half = (array.length-1) / 2; for (int i = half; i >= 0; i--) { maxHeap(array, array.length, i); } for (int i = array.length - 1; i >= 1; i--) { int temp = array[0]; array[0]=array[i]; array[i]=temp; maxHeap(array, i, 0); } }  static void Sort(int[] array); }
Heap { public static void Sort(int[] array) { if (array == null || array.length <= 1) { return; } int half = (array.length-1) / 2; for (int i = half; i >= 0; i--) { maxHeap(array, array.length, i); } for (int i = array.length - 1; i >= 1; i--) { int temp = array[0]; array[0]=array[i]; array[i]=temp; maxHeap(array, i, 0); } }  static void Sort(int[] array);  }