【发布时间】:2017-10-03 04:35:37
【问题描述】:
所以我们有一个作业来计算二叉搜索树中的节点,但是我们不允许使用全局变量或函数参数,因为我们得到了一个我们不应该更改的预制模板。我知道如何使用全局变量和函数参数来做到这一点,但没有它我不知道如何做到这一点,因为我不能使用局部变量。
我现在的代码:
int count() const
{
int st = 1;
if (left != NULL) {
st++;
left->count();
}
if (right != NULL) {
st++;
right->count();
}
return st;
}
【问题讨论】:
-
不允许使用全局变量或局部函数变量?
标签: c++ recursion binary-tree