CMSC-341, Fall 1999, Sections 0101
Binary Search Tree FIND Operation
// ----- elementAt ----
template
const Comparable *
BST::elementAt (BinaryNode *t) const
{
return (t == NULL ? ITEM_NOT_FOUND : t->element);
}
//----- public find ( ) ------------
template
const Comparable &
BST::find ( const Comparable & x) const
{
return elementAt ( find (x, root) );
}
//------ private find ( ) -----------
template
BinaryyNode *
BST::find (const Comparable & x, BinaryNode *t ) const
{
if (t == NULL)
return NULL;
else if ( x < t->element )
return find (x, t->left)
else if ( x > t->element )
return find (x, t->right)
else
return t;
}
Dennis Frey
Last modified: Sun Sep 26 23:18:55 EDT 1999