You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Heap (5)public void heapfyDown(int index) {int largerChild;Node top = heapArray[index]; // save rootwhile (index < currentSize / 2) // while node has at least one child{int leftChild = 2 * index + 1;int rightChild = leftChild + 1;// find larger childif (rightChild < currentSize && // (rightChild exists?)heapArray[leftChild].getKey() < heapArray[rightChild].getKey())largerChild = rightChild;elselargerChild = leftChild;// top >= largerChild?if (top.getKey() >= heapArray[largerChild].getKey())break;// shift child upheapArray[index] = heapArray[largerChild];index = largerChild; // go down} // end whileheapArray[index] = top; // root to index} // end trickleDown()28