首页 > 其他 > 详细

求二叉树第K层的节点个数+求二叉树叶子节点的个数

时间:2016-10-15 19:39:26      阅读:239      评论:0      收藏:0      [点我收藏+]

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;
    }

求二叉树第K层的节点个数+求二叉树叶子节点的个数

原文:http://www.cnblogs.com/qingjiaowoxiaoxioashou/p/5964963.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!