编程:统计二叉树中叶子结点的个数

利用数据结构的知识进行编程
用java来编程

第1个回答  2009-06-21
简单,但是不帮你做作业。 给你写个C的

int countLeafNode (TreeNode* node)
{
if (node->firstChild == NULL) return 1;
else {
TreeNode* curNode = node->firstChild;
int ret = 0;
while (curNode != NULL) {
rer += countLeafNode(curNode);
curNode = curNode->NextSibling;
}
return ret;
}
}本回答被网友采纳
第2个回答  2009-06-19
一棵非空的二叉树中,如果度为0的节点数为n0,度为2的节点数为n2,则n0=n2+1
相似回答
大家正在搜