private void fixdownMinWithComparator ( int k ) { int c = 2 * k ; while ( c <= size ) { int m = minChildOrGrandchildWithComparator ( k ) ; if ( m > c + 1 ) { // grandchild if ( comparator . compare ( array [ m ] , array [ k ] ) >= 0 ) { break ; } K tmp = array [ k ] ; array [ k ] = array [ m ] ; array [ m ] = tmp ; if ( comparator . compare ( array [ m ] , array [ m / 2 ] ) > 0 ) { tmp = array [ m ] ; array [ m ] = array [ m / 2 ] ; array [ m / 2 ] = tmp ; } // go down k = m ; c = 2 * k ; } else { // child if ( comparator . compare ( array [ m ] , array [ k ] ) < 0 ) { K tmp = array [ k ] ; array [ k ] = array [ m ] ; array [ m ] = tmp ; } break ; } } }
Downwards fix starting from a particular element at a minimum level . Performs comparisons using the comparator .