Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions HeapSort.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down