Examine the code below from the AVLTree class and explain in convincing detail what the possible child
Question:
Examine the code below from the AVLTree class and explain in convincing detail what the possible child configurations for the node to be removed all and how the code handles each of those cases. Be very specific in identifying each individual case and explaining how the code carries out the required work.
CODE:
private AvlNode remove( AnyType x, AvlNode t )
{
if( t == null )
return t; // Item not found; do nothing
int compareResult = x.compareTo( t.element );
if( compareResult < 0 )
t.left = remove( x, t.left );
else if( compareResult > 0 )
t.right = remove( x, t.right );
else if( t.left != null && t.right != null ) // Two children
{
t.element = findMin( t.right ).element;
t.right = remove( t.element, t.right );
}
else
t = ( t.left != null ) ? t.left : t.right;
return balance( t );
}
Income Tax Fundamentals 2013
ISBN: 9781285586618
31st Edition
Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill