Pabl0o0

heap

May 17th, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.20 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.     for(int i =0; i<h.heap.length;i++){
  12.         Random r = new Random();
  13.         h.heap[i] = r.nextInt(30);
  14.         for (int j =0; j<i;j++){
  15.             if(h.heap[j]==h.heap[i])
  16.                 h.heap[i] = r.nextInt(30);
  17.         }
  18.     }
  19.        
  20. /* 
  21.     h.heap[0]= 27;
  22.     h.heap[1]= 22;
  23.     h.heap[2]= 28;
  24.     h.heap[3]= 13;
  25.     h.heap[4]= 9;  
  26.     h.heap[5]= 16;
  27.     h.heap[6]= 15;
  28.     h.heap[7]= 4;
  29.     h.heap[8]= 11;
  30.     h.heap[9]= 19;
  31.     h.heap[10]= 14;
  32. */ 
  33.    
  34.     h.heapDisplay();
  35.     h.buildingHeap(h.heap);
  36.     System.out.println();
  37.     System.out.println("Bulding heap:");
  38.     h.heapDisplay();   
  39.     h.heapSort(h.heap);
  40.     System.out.println("After heap sort:");
  41.     h.heapDisplay();   
  42.     System.out.println("-------------------------------------------------------"); 
  43.     System.out.println("Enqueue");
  44.     Heap newH = new Heap(0);
  45.     newH.enqueue(1);
  46.     newH.enqueue(24);
  47.     newH.enqueue(9);
  48.     newH.enqueue(15);
  49.     newH.enqueue(7);
  50.     newH.enqueue(20);
  51.     newH.enqueue(0);
  52.     newH.enqueue(2);
  53.     newH.enqueue(10);
  54.     newH.heapDisplay();
  55.     System.out.println("Dequeue");
  56.     for(int i =0; i<newH.heap.length;i++)
  57.         System.out.print(newH.dequeue() +", ");
  58.    
  59.    
  60.    
  61.     }
  62.    
  63. }
Advertisement
Add Comment
Please, Sign In to add comment