【发布时间】:2013-05-18 00:03:06
【问题描述】:
在我的程序中,我在给定目标的同时递归地尝试在树中找到一个节点,但我无法让它工作!
Stree::Node * Stree::find_node(Node* cur, string target)
{
Node *tmp = cur;;
if(cur == NULL || tmp == NULL)
return NULL;
if(cur->m_city == target || tmp->m_city == target)
return cur;
if(find_node(tmp->m_left, target))
{
return tmp;
}
else return find_node(cur->m_right, target);
【问题讨论】:
-
出了什么问题?您介意给我们一个最小的完整示例吗?
-
如果要进行线性搜索,为什么还要使用树?树的要点通常是进行 O(log N) 搜索,但您没有这样做。