public void remove ( int node ) { if ( node == NIL ) { throw new IllegalArgumentException ( ) ; } if ( left ( node ) != NIL && right ( node ) != NIL ) { // inner node final int next = next ( node ) ; assert next != NIL ; swap ( node , next ) ; } assert left ( node ) == NIL || right ( node ) == NIL ; final int parent = parent ( node ) ; int child = left ( node ) ; if ( child == NIL ) { child = right ( node ) ; } if ( child == NIL ) { // no children if ( node == root ) { assert size ( ) == 1 : size ( ) ; root = NIL ; } else { if ( node == left ( parent ) ) { left ( parent , NIL ) ; } else { assert node == right ( parent ) ; right ( parent , NIL ) ; } } } else { // one single child if ( node == root ) { assert size ( ) == 2 ; root = child ; } else if ( node == left ( parent ) ) { left ( parent , child ) ; } else { assert node == right ( parent ) ; right ( parent , child ) ; } parent ( child , parent ) ; } release ( node ) ; rebalance ( parent ) ; }
Remove the specified node from the tree .