knightmareof
New member
I have wrote a simple heap sort code but can't get the heapify method right. Can someone please help me with this. My code is below if you would like to see what i have done so far.
public class HeapSort {
public static int[] heapify(int[] list) {
}
//Reheap. Used during actual sorting
public static int[] reheap(int[] list, int last) {
return (list);
}
//Sorting
public static int[] heapSort(int[] list) {
int last=list.length-1;
int temp;
//heapify the array
list=heapify(list);
System.out.print("Heapified list: ");
for(int x=0;x<list.length;x++) {
System.out.print(list[x]+", ");
}
while (last>0) {
//swap first and last elements
temp=list[0];
list[0]=list[last];
list[last]=temp;
last--;
list=reheap(list, last);
}
return(list);
}
public static int Switch(int node, int position){
int temp;
temp=position;
position=node;
node=temp;
return(node);
}
}
public class HeapSort {
public static int[] heapify(int[] list) {
}
//Reheap. Used during actual sorting
public static int[] reheap(int[] list, int last) {
return (list);
}
//Sorting
public static int[] heapSort(int[] list) {
int last=list.length-1;
int temp;
//heapify the array
list=heapify(list);
System.out.print("Heapified list: ");
for(int x=0;x<list.length;x++) {
System.out.print(list[x]+", ");
}
while (last>0) {
//swap first and last elements
temp=list[0];
list[0]=list[last];
list[last]=temp;
last--;
list=reheap(list, last);
}
return(list);
}
public static int Switch(int node, int position){
int temp;
temp=position;
position=node;
node=temp;
return(node);
}
}