CMSC-341, Fall 1999, Sections 0101

Binary Search Tree FIND Operation

// ----- elementAt ---- template <class Comparable> const Comparable * BST::elementAt (BinaryNode<Comparble> *t) const { return (t == NULL ? ITEM_NOT_FOUND : t->element); } //----- public find ( ) ------------ template <class Comparable> const Comparable & BST::find ( const Comparable & x) const { return elementAt ( find (x, root) ); } //------ private find ( ) ----------- template <class Comparable> BinaryyNode<Comparable> * BST::find (const Comparable & x, BinaryNode<Comparable> *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