Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1.  
  2.    
  3.     public void insert(E i) {
  4.        
  5.         if(heap.length == size)
  6.         {
  7.             doubleCapacity();
  8.         }
  9.        
  10.         int currentindex =size;
  11.         heap[currentindex] = i;
  12.         size++;
  13.         int parent = (int) Math.floor((currentindex-1)/2);
  14.        
  15.    
  16.        
  17.         while(heap[currentindex].compareTo(heap[parent]) <0)
  18.         {
  19.             E help = heap[parent];
  20.             heap[parent]=heap[currentindex];
  21.             heap[currentindex] = help; 
  22.             currentindex=parent;
  23.             parent = (int) Math.floor((currentindex-1)/2);
  24.            
  25.         }
  26.            
  27.            
  28.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement