Heap { public void maxHeapify(List<T> A, Comparator<T> comp, int i, int n) { System.out.println("maxHeapify. A: " + A + ", i: " + i + ", A[i]: " + A.get(i) + ", n: " + n); int largest; int l = getLeftChildIndex(A, i); int r = getRightChildIndex(A, i); System.out.println("l: " + l + ", r: " + r); if ((l < n) && (comp.compare(A.get(l), A.get(i)) > 0)) largest = l; else largest = i; if ((r < n) && (comp.compare(A.get(r), A.get(largest)) > 0)) largest = r; System.out.println("largest: " + largest); if (largest != i) { swap(A, i, largest); maxHeapify(A, comp, largest, n); } }  static void heapsort(List<T> A, Comparator<T> comp); static void heapsort(List<Integer> A); void heapsort(List<T> A, Comparator<T> comp, int n); void maxHeapify(List<T> A, Comparator<T> comp, int i, int n); void buildMaxHeap(List<T> A, Comparator<T> comp, int n);  }
@Test public void testMaxHeapify() { System.out.println("testMaxHeapify entry."); List<Integer> before = Arrays.asList(16, 4, 10, 14, 7, 9, 3, 2, 8, 1); List<Integer> expected = Arrays.asList(16, 14, 10, 8, 7, 9, 3, 2, 4, 1); List<Integer> after = new ArrayList<Integer>(before.size()); for(Integer i: before) after.add(i); tester.maxHeapify(after, comp, 1, after.size()); System.out.println("after: " + after); assertArrayEquals(expected.toArray(), after.toArray()); }