在二叉排序树(Binary Search Tree, BST)中,假设节点值互不相同。给定如下搜索函数:
bool find(Node* root, int x) {
while (root) {
if (root->val == x) return true;
root = (x < root->val) ? root->left : root->right;
}
return false;
}