编写一个函数,统计二叉树中叶子节点个数

2025-04-13 14:07:34
推荐回答(1个)
回答1:

int count(binNode *root)

{
int leaf = 0;
if (! root)
{
if (! root->lchild && ! root->rchild)
leaf ++;
leaf += count(root->lchild);
leaf += count(root->rchild);
}
return leaf;
}