Pabl0o0

Untitled

May 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.60 KB | None | 0 0
  1. package kopiec;
  2.  
  3. import java.util.Random;
  4.  
  5. public class Test {
  6.  
  7. public static void main(String args[]){
  8.  
  9. Heap h = new Heap(11);
  10.  
  11.  
  12. for(int i =0; i<h.heap.length;i++){
  13. Random r = new Random();
  14. h.heap[i] = r.nextInt(30);
  15. for (int j =0; j<i;j++){
  16. if(h.heap[j]==h.heap[i])
  17. h.heap[i] = r.nextInt(30);
  18. }
  19. }
  20.  
  21.  
  22. /* h.heap[0]= 11;
  23. h.heap[1]= 24;
  24. h.heap[2]= 38;
  25. h.heap[3]= 2;
  26. h.heap[4]= 18;
  27. h.heap[5]= 15;
  28. h.heap[6]= 40;
  29. h.heap[7]= 55;
  30. h.heap[8]= 28;
  31. h.heap[9]= 7;
  32. h.heap[10]= 33;
  33. */
  34. /*
  35. h.heap[0]= 27;
  36. h.heap[1]= 22;
  37. h.heap[2]= 28;
  38. h.heap[3]= 13;
  39. h.heap[4]= 9;
  40. h.heap[5]= 16;
  41. h.heap[6]= 15;
  42. h.heap[7]= 4;
  43. h.heap[8]= 11;
  44. h.heap[9]= 19;
  45. h.heap[10]= 14;
  46. */
  47.  
  48. h.heapDisplay();
  49. h.buildingHeap(h.heap);
  50. System.out.println();
  51. System.out.println("Bulding heap:");
  52. h.heapDisplay();
  53. h.heapSort(h.heap);
  54. System.out.println("After heap sort:");
  55. h.heapDisplay();
  56. System.out.println("-------------------------------------------------------");
  57. System.out.println("Enqueue");
  58. Heap newH = new Heap(0);
  59. newH.enqueue(1);
  60. newH.enqueue(24);
  61. newH.enqueue(9);
  62. newH.enqueue(15);
  63. newH.enqueue(7);
  64. newH.heapDisplay();
  65. System.out.println(newH.dequeue());
  66. System.out.println(newH.dequeue());
  67. System.out.println(newH.dequeue());
  68. System.out.println(newH.dequeue());
  69.  
  70. /*
  71. System.out.println("Enqueue one element - for example 0");
  72. h.enqueue(0);
  73. h.heapDisplay();
  74.  
  75. h.heapSort(h.heap);
  76. System.out.println();
  77. System.out.println("After heap sort:");
  78. h.heapDisplay();
  79. */
  80. // h.dequeue();
  81. // h.heapDisplay();
  82.  
  83.  
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment