Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1.  
  2. public class heapsort {
  3.  
  4. public heaport(int[] a){
  5. int n = a.length;
  6. for(int i = n - 1; i >=0; i--){ //why is it "i >= 0"
  7. buildheap(a,n,i);
  8. }
  9. for(int i = n-1; i >= 0; i--){
  10. int temp = a[0];
  11. a[i] = a[0];
  12. temp = a[i];
  13.  
  14. buildheap(a,i,0);
  15. }
  16. }
  17.  
  18. 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
  19.  
  20.  
  21. }
  22.  
  23. public static void maxheap(int a){ //swap first w/ last and then buildheap again
  24.  
  25. }
  26.  
  27.  
  28.  
  29. public static void swap(int[] a, int i, int j) {
  30. int temp = a[i];
  31. a[i] = a[j];
  32. a[j] = temp;
  33. }
  34.  
  35. public static void printArray(int[] a) {
  36. for (int i = 0; i < a.length; i++) {
  37. System.out.print(a[i] + ",");
  38. }System.out.println();
  39. }
  40.  
  41. public static void main(String[] args) {
  42. int[] a = new int[] {1,3,5,6,8,2,1000,123,7,9};
  43. int[] b = new int[] {1,3,5,6,8,2,1000,13123,7,9};
  44. heapsort bob = new heapsort(a);
  45. heapsort bob1 = new heapsort(b);
  46.  
  47. printArray(a);
  48. printArray(b);
  49.  
  50.  
  51.  
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement