【发布时间】:2014-11-01 00:46:08
【问题描述】:
int count(Node node) {
if (node == null)
return 0;
int r = count (node.right);
int l = count (node.left);
return 1 + r + l;
}
此函数返回以节点为根的二叉树中的节点数。有几篇文章说这是前序遍历,但对我来说这看起来像是后序遍历,因为我们在访问根之前访问了左右部分。我在这里错了吗?还是我的“访问”概念有问题?
【问题讨论】:
标签: java algorithm tree binary-tree