CMSC-341, Fall 1999, Sections 0101
Binary Search Tree INSERT Operation
//--- public insert ( )-------
template
void
BST::insert (const Comparable & x)
{
insert (x, root);
}
// --- private insert ( ) ------
template
void
BST::
insert (const Comparable & x, BinaryNode * &t )
{
if (t == NULL)
t = new BinaryNode (x, NULL, NULL);
else if (x < t->element)
insert (x, t->left);
else if (t->element < x)
insert (x, t->right);
else
; // Duplicate, do nothing
}
Dennis Frey
Last modified: Sun Sep 26 20:50:47 EDT 1999