Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class heapsort {
- public heaport(int[] a){
- int n = a.length;
- for(int i = n - 1; i >=0; i--){ //why is it "i >= 0"
- buildheap(a,n,i);
- }
- for(int i = n-1; i >= 0; i--){
- int temp = a[0];
- a[i] = a[0];
- temp = a[i];
- buildheap(a,i,0);
- }
- }
- public static void buildheap(int[] a, int length, int i){ //int i is the starting node where you begin to check children from top to bottom. buildheap checks children from top to bottom starting at node i
- }
- public static void maxheap(int a){ //swap first w/ last and then buildheap again
- }
- public static void swap(int[] a, int i, int j) {
- int temp = a[i];
- a[i] = a[j];
- a[j] = temp;
- }
- public static void printArray(int[] a) {
- for (int i = 0; i < a.length; i++) {
- System.out.print(a[i] + ",");
- }System.out.println();
- }
- public static void main(String[] args) {
- int[] a = new int[] {1,3,5,6,8,2,1000,123,7,9};
- int[] b = new int[] {1,3,5,6,8,2,1000,13123,7,9};
- heapsort bob = new heapsort(a);
- heapsort bob1 = new heapsort(b);
- printArray(a);
- printArray(b);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement