如果是空树,返回0.否则叶子节点个数为左叶子结点+右叶子结点
int LeafCount(BiTree p) {
if (p == NULL)
return 0;
if (p->lchild == NULL && p->rchild == NULL)
return 1;
else
return LeafCount(p->lchild) + LeafCount(p->rchild);
}
如果是空树,返回0.否则叶子节点个数为左叶子结点+右叶子结点
int LeafCount(BiTree p) {
if (p == NULL)
return 0;
if (p->lchild == NULL && p->rchild == NULL)
return 1;
else
return LeafCount(p->lchild) + LeafCount(p->rchild);
}