【发布时间】:2017-04-17 11:56:55
【问题描述】:
我必须在二叉树中实现字符串搜索方法。它以node*为输入,再次输出node*。
问题是由于某些指针异常而无法正常工作,它给了我错误。
如果我在某些时候不清楚,请告诉我。
提前谢谢你
-var-create: 无法创建变量对象错误
zoo_tree::node* tree_tools::search(zoo_tree::node* from,string animal) {
if (from != NULL) {
if (from->question == animal) {
return from;
}
if (from->question != animal) {
search(from->left, animal);
search(from->right, animal);
}
}
return NULL;
}
但是,上面的代码可以工作,有什么区别?
zoo_tree::node* tree_tools::search(zoo_tree::node* from,string animal) {
if (from == NULL)
return NULL;
if (from->question == animal)
return from;
if (from->question != animal)
{
search(from->left, animal);
search(from->right, animal);
}
}
【问题讨论】:
标签: c++ recursion binary-tree binary-search-tree