gpt4 book ai didi

c++ - 作业求助,无效参数二叉树

转载 作者:行者123 更新时间:2023-11-28 03:44:13 25 4
gpt4 key购买 nike

我的作业有问题。奇怪的是,treeHeight 的功能起作用了。它是由本书提供的。我为这个家庭作业制作了 nodeCount 和 leaveCount,当作者制作的作业没有时,我得到了这些构建错误

构建错误:

1>  testProgBinarySearchTree.cpp
1>testProgBinarySearchTree.cpp(49): error C2660: 'binaryTreeType<elemType>::nodeCount' : function does not take 0 arguments
1> with
1> [
1> elemType=int
1> ]
1>testProgBinarySearchTree.cpp(50): error C2660: 'binaryTreeType<elemType>::leavesCount' : function does not take 0 arguments
1> with
1> [
1> elemType=int
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

主要源码:

cout << endl<<"Line 24: Tree Height: "
<< treeRoot.treeHeight() << endl; //Line 24

cout << endl << "The node count is: " << treeRoot.nodeCount();
cout << endl << "The leaf count is: " << treeRoot.leavesCount();

类:

int height(binaryTreeNode<elemType> *p) const;
//Function to return the height of the binary tree
//to which p points.
int max(int x, int y) const;
//Returns the larger of x and y.
int nodeCount(binaryTreeNode<elemType> *p) const;
//Function to return the number of nodes in the binary
//tree to which p points
int leavesCount(binaryTreeNode<elemType> *p) const;
//Function to return the number of leaves in the binary
//tree to which p points

template <class elemType>
int binaryTreeType<elemType>::height(binaryTreeNode<elemType> *p) const
{
if (p == NULL)
return 0;
else
return 1 + max(height(p->llink), height(p->rlink));
}

template <class elemType>
int binaryTreeType<elemType>::max(int x, int y) const
{
if (x >= y)
return x;
else
return y;
}

template <class elemType>
int binaryTreeType<elemType>::nodeCount(binaryTreeNode<elemType> *p) const
{
if (p == null)
return 0;
else
return nodeCount(p->llink) + nodeCount(p->rlink) + 1;
}

template <class elemType>
int binaryTreeType<elemType>::leavesCount(binaryTreeNode<elemType> *p) const
{
if (p == null)
return 0;
else
if ( leavesCount(p->llink) == 0 && leavesCount(p->rlink) == 0)
return 1;
else
return leavesCount(p->llink) + leavesCount (p->rlink);
}

搞清楚谢谢。另一个函数用相似的名称调用它,我错过了它,已修复并感谢您的帮助

最佳答案

错误消息准确地告诉您问题出在哪里;这些函数需要参数。你在没有参数的情况下调用它们。

关于c++ - 作业求助,无效参数二叉树,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8116102/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com