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

相关文章:

  • 2021-09-17
  • 2021-11-12
  • 2022-12-23
  • 2021-08-21
  • 2021-06-25
  • 2021-07-05
  • 2022-03-05
  • 2022-12-23
猜你喜欢
  • 2021-07-01
  • 2022-02-08
  • 2022-02-01
  • 2022-12-23
相关资源
相似解决方案