二进制搜索树,高度

Binary Search Tree, height

本文关键字:高度 搜索树 二进制      更新时间:2023-10-16

这是我在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)
           ^^

就是你所需要的。