private void downHeap ( ) { E elem = storage . array [ 0 ] ; int currIdx = 0 ; while ( 2 * currIdx < size ) { int leftChildIdx = 2 * currIdx ; E leftChild = storage . array [ leftChildIdx ] ; if ( comparator . compare ( elem , leftChild ) > 0 ) { storage . array [ currIdx ] = leftChild ; storage . array [ leftChildIdx ] = elem ; currIdx = leftChildIdx ; } else if ( 2 * currIdx + 1 < size ) { int rightChildIdx = 2 * currIdx + 1 ; E rightChild = storage . array [ rightChildIdx ] ; if ( comparator . compare ( elem , rightChild ) > 0 ) { storage . array [ currIdx ] = rightChild ; storage . array [ rightChildIdx ] = elem ; currIdx = rightChildIdx ; } else { return ; } } else { return ; } } }
Sifts the topmost element down into the heap until the heap condition is restored .