//二叉树叶子节点的数目
size_t _GetLeafCount(BinaryTreeNode<T>* pRoot)
{
if (pRoot == NULL)
return 0;
if (NULL == pRoot->_pLeftChild && NULL == pRoot->_pRightChild)
return 1;
return _GetLeafCount(pRoot->_pLeftChild) + _GetLeafCount(pRoot->_pRightChild);
}
//二叉树第k层的节点数目
size_t _GetLevel_K_Count(BinaryTreeNode<T>* pRoot,int k)
{
if (pRoot == NULL || k<=0 )
return 0;
if (pRoot != NULL && k == 1)
return 1;
return _GetLevel_K_Count(pRoot->_pLeftChild, k-1) + _GetLevel_K_Count(pRoot->_pRightChild, k-1);
}
//二叉树第k层的叶子节点数目
size_t _GetLevel_K_LeafCount(BinaryTreeNode<T>* pRoot, int k)
{
if (pRoot == NULL || k <= 0)
return 0;
if (pRoot ->_pLeftChild == NULL && pRoot->_pRightChild == NULL && k == 1)
return 1;
return _GetLevel_K_LeafCount(pRoot->_pLeftChild, k - 1) + _GetLevel_K_LeafCount(pRoot->_pRightChild, k - 1);
}
二叉树叶子节点的数目&二叉树第k层节点的数目&二叉树第k层叶子节点的数目
最新推荐文章于 2020-10-06 10:06:12 发布