【发布时间】:2017-11-06 16:23:05
【问题描述】:
我知道如何通过递归找到树的大小,但我不确定如何在没有递归的情况下找到它。 这是我到目前为止所拥有的。我认为是我的 if 语句阻止我遍历树。
public int size() {
size = 0;
NodeWord current = root;
while(current != null) {
if(current.left != null) {
size++;
}
else {
current = current.right;
}
}
return size;
}
【问题讨论】:
-
你能通过编辑这个问题发布你的代码吗?请向我们展示您尝试做的事情。