作业帮助,无效的参数二进制树
Homework help, invalid parameters binary trees
我的家庭作业有问题。奇怪的是,treeHeight的功能起作用了。它是由这本书提供的。我为这个作业做了nodeCount和leavesCount,当作者做的那个没有时,我得到了这些构建错误
构建错误:
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);
}
想清楚了,谢谢。另一个函数用类似的名称调用它,我错过了它,修复了它,并感谢
错误消息告诉您精确地问题是什么;这些函数需要参数。你在没有争论的情况下给他们打电话。
int binaryTreeType<elemType>::nodeCount(binaryTreeNode<elemType> *p) const
cout << endl << "The node count is: " << treeRoot.nodeCount();
您的错误表明nodeCount
不接受零个参数。从您的函数签名,您需要传入一个binaryTreeNode<elemType> *p
,而您调用它的方式是不传入任何内容
从代码中看,您应该将根节点传入。
相关文章:
- 二进制数据作为命令行参数
- 操作员超载;必须是二进制操作员(具有3个参数)
- 使用二进制参数调用LUA方法
- 二进制搜索树插入带参数参考
- 自定义一元/二进制Expr() eigen3 的参数
- C 模板二进制搜索树 - 参数列表错误
- C 功能具有3个参数,可在通用二进制输入中读取
- 具有三个参数的C 递归二进制搜索
- 将二进制文件加载到eigen矩阵中时,请删除潜在的冗余模板参数
- 修改filter_iterator谓词以接受BOOST中的两个参数(二进制fn)
- 转换具有不同参数类型的二进制运算函数
- 在C++中更改参数名称时的二进制兼容性
- 我的二进制搜索树 c++ 的递归函数中的错误 C2784 无法推断模板参数
- 将文件的每一行作为命令行参数传递给二进制文件
- C++二进制树遍历和函数指针参数
- C++ 集<>类对象。使用自己的比较器给出错误:C2804:二进制'operator <'参数过多
- 作业帮助,无效的参数二进制树
- 用类和函子作为模板参数实现一个泛型二进制函数
- 二进制泛型lambda不匹配ptr-to-function参数
- 读取图像的二进制数据作为命令行参数