求二叉树第K层的节点个数+求二叉树叶子节点的个数
size_t _FindLeafSize(Node* root) //求二叉树叶子节点的个数
{
//static size_t count = 0;
if (root == NULL)
return 0;
if (root->_left == NULL&&root->_right == NULL);
return 1;
return _FindLeafSize(root->_right) + _FindLeafSize(root->_left);
}
//求二叉树第K层的节点个数
size_t _FindKLevel(Node* root, size_t k, size_t level) //找二叉树中第K层节点
{
static size_t num = 0;
if (root == NULL)
return 0;
if (level == k)
{
++num;
return num;
}
_FindKLevel(root->_left, k, level + 1);
_FindKLevel(root->_right, k, level + 1);
return num;
}