diff --git a/HeapSort.java b/HeapSort.java index e7da94b..e584ba2 100644 --- a/HeapSort.java +++ b/HeapSort.java @@ -8,24 +8,25 @@ * */ public class Heap { + /** * heap sort (case-insensitive) * @param x array of subjects * @param y associated array * @param n problem size */ - public static void sortHeap (String[] x, String[] y, int n ) { + public static void sortHeap (String[] x, Integer[] y, int n ) { this.construct(x,y,n); this.sort(x,y,n); } - + /** * heap sort (case-insensitive) * @param x array of subjects * @param y associated array * @param n problem size */ - public static void sortHeap (String[] x, Integer[] y, int n ) { + public static void sortHeap (String[] x, String[] y, int n ) { this.construct(x,y,n); this.sort(x,y,n); } @@ -122,12 +123,6 @@ private static void sort(String[] x, String[] y, int n){ } } - /** - * Performs sortdown of a max-oriented heap to produce a sorted array - * @param x input array organized as max-oriented heap - * @param y associated array - * @param n size of input array - */ private static void sort(String[] x, Integer[] y, int n){ int end = n - 1; @@ -137,7 +132,6 @@ private static void sort(String[] x, Integer[] y, int n){ exchange(x, y, 0, end); - //fix heap order by checking root node with child nodes and switching where necessary int i = 0; while (2*i+1 < end && 2*i+2 < end && ((lower(x[2*i+1]).compareTo(lower(x[i])) > 0) || (lower(x[2*i+2]).compareTo(lower(x[i])) > 0))){ //If at least one of the children is non-null and bigger