Question: my code: public class Sorts { public static > void heapSort ( T [ ] array ) { int n = array.length; for ( int

my code:
public class Sorts {
public static > void heapSort(T[] array){
int n = array.length;
for (int i = n /2-1; i >=0; i--){
siftDown(array, n, i);
}
for (int i = n -1; i >=0; i--){
T temp = array[0];
array[0]= array[i];
array[i]= temp;
siftDown(array, i,0);
}
}
private static > void siftDown(T[] array, int n, int i){
T temp = array[i];
int child;
while ((child =2* i +1) n){
if (child +1 n && array[child +1].compareTo(array[child])>0){
child++;
}
if (array[child].compareTo(temp)>0){
array[i]= array[child];
i = child;
} else {
break;
}
}
array[i]= temp;
}
}
Want to double-check/ fix my code. professor isn't helpful at all
Project 3
Due Nov 7 by 11:59pm
Points 100
Submitting a file upload
File Types java
Fast Sorting Algorithms
Implement a fast sorting algorithm as described in class. Here
is some example code beta to use as a guideline.
You need only implement the sorting algorithm; the main
method will be provided for you.
You must hand in the Sorts class with the
heapSort sorting algorithm implemented. This is the only
file you should hand in. The heading of the method is as in the
provided file. Do not change it or you will lose credit!
my code: public class Sorts { public static >

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!