第1个回答 2008-01-12
用递归啊,除了叶子节点以外,每个节点都有左子树和右子树,只要判断子节点不为空就用递归调用函数统一子树的节点数,例如
f(T)=f(L)+f(R)+1;
节点总数等于左子树的节点数+右子树的节点数+1
第2个回答 推荐于2018-04-04
int countnode(bt *h) //其中bt是二叉树的结点(结构体)
{if(!bt)return 0;
int a,b;
a=countnode(h^.lchild);
b=countnode(h^.rchild);
return a+b+1;
}本回答被网友采纳
第3个回答 2019-08-09
int
leavecount(bitree
t)
{
int
i=0;
if(t->leftchild)
{
i++;
i+=leavecount(bitree
t->leftchild);
}
if(t->rightchild)
{
i++;
i+=leavecount(bitree
t->rightchild);
}
return
i;
}
第4个回答 2008-01-12
不明白呀,能说的具体点么?