【发布时间】:2020-04-17 02:50:09
【问题描述】:
我正在尝试将字符串与二叉搜索树进行比较,下面的代码在第一个搜索树上工作,但在其他所有搜索树上都失败了——即使我已经检查以确保它正在递归检查树.谢谢!
bool BST::compareIt(Node* current, string name)
{
if (name == current->title)
return true;
if (current->left != NULL)
compareIt(current->left, name);
if (current->right != NULL)
compareIt(current->right, name);
return false;
}
我
【问题讨论】:
-
就我个人而言,我不喜欢使用字符串。我使用 char* 代替...
-
@mlwn 为什么会这样?字符串有什么问题?
-
大多数时候,我为有限的处理器编写代码,并且我喜欢控制所使用的内存......我猜现代机器上的字符串没有问题
-
@mlwn 这很有趣,但不太可能帮助澄清这个问题或帮助这个问题的读者。
-
@aschepler ...我什至对你的评论投了赞成票...你是对的..
标签: c++ string binary-search-tree