protected void delete ( Node < K , V > n ) { if ( n == root ) { deleteMin ( ) ; return ; } if ( n . y_s == null ) { throw new IllegalArgumentException ( "Invalid handle!" ) ; } // disconnect and union children of node Node < K , V > childTree = unlinkAndUnionChildren ( n ) ; // find parent Node < K , V > p = getParent ( n ) ; // link children tree in place of node if ( childTree == null ) { // no children, just unlink from parent if ( p . o_c == n ) { if ( n . y_s == p ) { p . o_c = null ; } else { p . o_c = n . y_s ; } } else { p . o_c . y_s = p ; } } else { // link children tree to parent if ( p . o_c == n ) { childTree . y_s = n . y_s ; p . o_c = childTree ; } else { p . o_c . y_s = childTree ; childTree . y_s = p ; } } size -- ; n . o_c = null ; n . y_s = null ; }
Delete a node from the heap .