有誰知道如何使用循環遍歷二叉搜索樹而不是遞歸嗎?通過循環遍歷二叉搜索樹而不是遞歸
我有遞歸方法
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;
}
請縮進您的代碼。我真的不能看,直到它縮進... – 2014-12-04 02:50:10
是的,我知道。你有沒有想過呢? – zapl 2014-12-04 02:50:42