Example #1
0
 public void trickleUp(int index) {
   // TODO Auto-generated method stub
   int parent = (index - 1) / 2;
   Node bottom = heapArray[index];
   while (index > 0 && heapArray[parent].getKey() < bottom.getKey()) {
     heapArray[index] = heapArray[parent];
     index = parent;
     parent = (parent - 1) / 2;
   }
   heapArray[index] = bottom;
 }
Example #2
0
 public void tickelDown(int index) {
   // TODO Auto-generated method stub
   int largerChildren;
   Node top = heapArray[index];
   while (index < currentSize / 2) {
     int leftChild = 2 * index + 1;
     int rightChild = leftChild + 1; // or 2*index+2;
     if (rightChild < currentSize
         && heapArray[leftChild].getKey() < heapArray[rightChild].getKey()) {
       largerChildren = rightChild;
     } else {
       largerChildren = leftChild;
     }
     if (top.getKey() >= heapArray[largerChildren].getKey()) {
       break;
     }
     heapArray[index] = heapArray[largerChildren];
     index = largerChildren;
   }
   heapArray[index] = top;
 }