CMSC-341, Fall 1999, Sections 0101
Binary Search Tree REMOVE Operation
template
void BST::
remove (const Comparable & x, BinaryNode * & t)
{
if (t == NULL)
return;
if (x < t->element)
remove (t->left);
else if (x > t->element)
remove (t->right);
else if (t->left != NULL && t->right != NULL)
{
t->element = findMin (t->right)->element;
remove (t->element, t->right);
}
else
{
BinaryNode *oldNode = t;
t = t->left != NULL ? t->left : t->right;
delete oldNode;
}
}
Dennis Frey
Last modified: Sun Sep 26 20:53:16 EDT 1999