【问题标题】:Count Nodes in BSTBST 中的节点数
【发布时间】:2021-10-17 04:41:22
【问题描述】:

我正在尝试创建一个函数来计算插入 BST 中的节点数。我不确定为什么我的访问权限不好。非常感谢您的帮助!

我正在尝试实现 totl,它计算树中的单词数,包括未添加到树中的重复单词(但增加了 m_count) 但是,我对此的访问权限很差:

int totl(T * curr) const
{
    if(root==nullptr)return 0;
    else
    {
        return root->m_count + totl(root->m_left) + totl(root->m_right);
    }
}

【问题讨论】:

  • @evg 我把文本最小化了,但是如果我不提供代码就很难找到问题
  • 请提供一个reproducible(可编译和可执行)的例子。现在我们甚至看不到totalWords_aux 的声明。
  • @Evg 谢谢你的澄清,我刚刚添加了类和函数声明
  • curr 参数在 aux 函数中未使用?

标签: c++ recursion tree binary-tree binary-search-tree


【解决方案1】:

代码应该在递归函数中使用curr而不是root,然后在main中调用totl(root)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-08
    • 2012-10-07
    • 1970-01-01
    • 1970-01-01
    • 2013-09-01
    • 2014-05-26
    相关资源
    最近更新 更多