@Test public void ascendingOrderSort() { Integer[] array = { 5, 4, 3, 2, 1 }; Integer[] sorted = HeapSort.heapSort(array, ascOrderComparator); assertArrayEquals("Failure => Array returned is not sorted.", sorted, new Integer[] { 1, 2, 3, 4, 5 }); }
public static <T> T[] heapSort(T[] array, Comparator<T> comparator) { Heap<T> heap = new SimpleHeapImpl<T>(array, comparator); for (int index = array.length - 1; !heap.isEmpty(); index--) { try { array[index] = heap.pop(); } catch (EmptyHeapException e) { throw new RuntimeException(e); } } return array; }
HeapSort { public static <T> T[] heapSort(T[] array, Comparator<T> comparator) { Heap<T> heap = new SimpleHeapImpl<T>(array, comparator); for (int index = array.length - 1; !heap.isEmpty(); index--) { try { array[index] = heap.pop(); } catch (EmptyHeapException e) { throw new RuntimeException(e); } } return array; } }
HeapSort { public static <T> T[] heapSort(T[] array, Comparator<T> comparator) { Heap<T> heap = new SimpleHeapImpl<T>(array, comparator); for (int index = array.length - 1; !heap.isEmpty(); index--) { try { array[index] = heap.pop(); } catch (EmptyHeapException e) { throw new RuntimeException(e); } } return array; }  }
HeapSort { public static <T> T[] heapSort(T[] array, Comparator<T> comparator) { Heap<T> heap = new SimpleHeapImpl<T>(array, comparator); for (int index = array.length - 1; !heap.isEmpty(); index--) { try { array[index] = heap.pop(); } catch (EmptyHeapException e) { throw new RuntimeException(e); } } return array; }  static T[] heapSort(T[] array, Comparator<T> comparator); }
HeapSort { public static <T> T[] heapSort(T[] array, Comparator<T> comparator) { Heap<T> heap = new SimpleHeapImpl<T>(array, comparator); for (int index = array.length - 1; !heap.isEmpty(); index--) { try { array[index] = heap.pop(); } catch (EmptyHeapException e) { throw new RuntimeException(e); } } return array; }  static T[] heapSort(T[] array, Comparator<T> comparator);  }