c++ - 二叉搜索树,高度

标签 c++ binary-tree binary-search

<分区>

这是我在 bst 中的高度函数。 cpp

int IntBinaryTree::getHeight(TreeNode * nodePtr)
{
  if(nodePtr = NULL)
    return 0;
  else
    return (max(1+getHeight(nodePtr->left), 1+getHeight(nodePtr->right)));
}

当我在 main() 中调用它时。我得到一个错误。

这是我的主要()

int main {
  IntBinaryTree tree;
   .... 
  tree. getHeight(); 
  return 0; 
}

最佳答案

你没有说是什么错误,但看起来像是在改变:

if(nodePtr = NULL)

if(nodePtr == NULL)
           ^^

是你需要的。

关于c++ - 二叉搜索树,高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25675293/

相关文章:

java - JNI : passing integer array from Java to C

c++ - 指向指针数组的指针!如何删除?

c - 如何在不导致段错误的情况下更新 bst 结构中的字符指针?

java - 为什么二分查找返回-1

c# - 按 ID 的 BinarySearch 对象数组

c++ - QTableWidget,居中cellWidgets

C++ OpenCV VideoCapture 在不同机器上的工作方式不同

Python 二叉树打印具有两个正好两个子节点的节点

algorithm - 需要找到我的算法的时间和空间复杂度

c++ - 通过修改二进制搜索算法来改进它,使其在大量单词(单词列表)中搜索单词时工作得更快