【发布时间】:2021-11-04 20:56:32
【问题描述】:
struct node {
int data;
struct node *left; /* left tree part */
struct node *right; /* right tree part */
};
bool search(struct node *root, int element) {
if ( root -> data == element) {
return true;
}
if (root->data < element) {
search (root->right, element);
}
if (root->data > element) {
search(root->left, element);
}
return false;
}
如果在二叉搜索树中找到给定元素,我希望该程序返回 true。否则返回假。这个递归进度有什么问题?
【问题讨论】:
-
如果
root->right为空怎么办? -
你应该对递归调用的结果做一些事情。
标签: c binary-search-tree