数据结构递归返回二叉树双分支节点个数

int k;
int count(bintnode * t) {
if (!t) { return 0; }
if (t)
{
k = count(t->lchild);
k = k + count(t->rchild);
if (t->lchild&&t->lchild)
{
k++;
return k;
}
}
}
这样对吗

不对,k 不能全局变量,否则每次调用子节点会把之前的通缉都清掉了,

img

把 int k 放到方法内,作为局部变量就可以