【问题1】计算二叉树中叶子节点的数目
int countLeafNodes(BTreeNode *root) {
if (root == NULL)
return 0;
if (root->leftchild == NULL && root->rightchild == NULL)
return 1;
return countLeafNodes(root->leftchild) + countLeafNodes(root->rightchild);
}
【问题2】计算二叉树中所有节点数目
int countAllNodes(BTreeNode *root) {
if (root == NULL)
return 0;
return countAllNodes(root->leftchild) + countAllNodes(root->rightchild) + 1;
}