二叉树叶子节点的数目&二叉树第k层节点的数目&二叉树第k层叶子节点的数目

来源:互联网 发布:mac安装微软雅黑字体 编辑:程序博客网 时间:2024/04/27 19:15
//二叉树叶子节点的数目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);}
阅读全文
0 0
原创粉丝点击