Implementing Binary Search
template <typename T, class P>
typename BST<T,P>::Iterator BST<T,P>::Includes (const T& t) const
{
Node * n = root_;
while(n != nullptr)
{
if (pred_(t,n->value_)) // go left
n = n->lchild_;
else if (pred_(n->value_,t)) // go right
n = n->rchild_;
else // found
return (Iterator)n; // convert to iterator and return
}
return End();
}
- Problem: what is an Iterator?
- Several answers to this question in later chapter that make the code above work.
- What other safe thing can we return and still be useful?