@ SuppressWarnings ( "unchecked" ) private void fixdownMax ( int k ) { int c = 2 * k ; while ( c <= size ) { int m = maxChildOrGrandchild ( k ) ; if ( m > c + 1 ) { // grandchild if ( ( ( Comparable < ? super K > ) array [ m ] ) . compareTo ( array [ k ] ) <= 0 ) { break ; } K tmp = array [ k ] ; array [ k ] = array [ m ] ; array [ m ] = tmp ; if ( ( ( Comparable < ? super K > ) array [ m ] ) . compareTo ( 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 ( ( ( Comparable < ? super K > ) array [ m ] ) . compareTo ( array [ k ] ) > 0 ) { K tmp = array [ k ] ; array [ k ] = array [ m ] ; array [ m ] = tmp ; } break ; } } }
Downwards fix starting from a particular element at a maximum level .