【发布时间】:2014-12-04 02:48:31
【问题描述】:
有谁知道如何使用循环而不是递归来遍历二叉搜索树?
我有递归方法
public static int countMatches(BinaryNodeInterface<Integer> tree, Integer key)
{
int matches = 0;
if (tree != null)
{
if (tree.getData().equals(key))
matches++;
matches += countMatches(tree.getLeftChild(), key);
matches += countMatches(tree.getRightChild(), key);
}
return matches;
}
【问题讨论】:
-
请缩进您的代码。在缩进之前我无法真正查看...
-
是的,我知道。你也想通了吗?
标签: java tree binary-tree binary-search-tree tree-traversal