更新时间:2015-11-21 19:53:15浏览次数:1+次
template <class T>
ResultCode BSTree<T>::Search(T & x) const {
return Search(root,x);
}
template <class T>
ResultCode BSTree<T>::Search(BTNode<T> *p, T & x) const{
if (!p) return NotPresent;
else if (x<p->element) return Search(p->lChild,x);
else if(x>p->element) return Search(p->rChild,x);
else {
x=p->element;return Success;
}
}
template <class T>
ResultCode BSTree<T>::Search(T & x) const {
BTNode<T> *p=root;
while (p) {
if ( x < p->element) p=p->lChild;
else if (x > p->element) p=p->rChild;
else {
x=p->element;
return Success;
}
}
return NotPresent;
}
相关资讯