private void reBalance ( DeleteStack . HeightNote xx , GBSNode bparent , GBSNode bpoint , GBSNode bnext ) { xx . bnew = bpoint ; /* Default for next time */ if ( bpoint . leftChild ( ) == bnext ) /* We deleted from left side */ { /* Check for RR or RL Rotation */ switch ( bpoint . balance ( ) ) /* Look at ORIGINAL Balance Factor */ { case 0 : /* Have deleted a left node of a balanced*/ bpoint . setBalance ( 1 ) ; /* tree. Now right heavy. */ break ; case 1 : /* Deleted left node of right heavy */ rotateRight ( xx , bparent , bpoint ) ; /* Need to re-balance */ break ; case - 1 : /* Deleted left node of left-heavy tree */ bpoint . clearBalance ( ) ; /* It becomes balanced & depth decreases */ xx . depthDecrease = true ; break ; default : throw new RuntimeException ( "bpoint.balance() = " + bpoint . balance ( ) ) ; } } else /* We deleted from right side */ { /* Check for LL or LR Rotation */ switch ( bpoint . balance ( ) ) /* Look at ORIGINAL Balance Factor */ { case 0 : /* Deleted a right node of a balanced */ bpoint . setBalance ( - 1 ) ; /* tree. Now left-heavy */ break ; case - 1 : /* Deleted right node of left-heavy */ rotateLeft ( xx , bparent , bpoint ) ; /* Need to re-balance */ break ; case 1 : /* Deleted a right node of a right-heavy */ bpoint . clearBalance ( ) ; /* It become balanced & depth decreases */ xx . depthDecrease = true ; break ; default : throw new RuntimeException ( "bpoint.balance() = " + bpoint . balance ( ) ) ; } } }
Method reBalance .