二进制表达式树c++构建函数
Binary Expression Tree c++ Build Function
所以我要上一堂计算机科学课,我们必须构建一个二进制表达式树,这是我目前所拥有的:
void buildtree(string str)
{
string tmp;
stack<char> opstack;
stack<BTNP> treeStack;
double value;
int i = 0;
while(i < str.length)
{
while(isspace(str[i++]))
{
if(str[i] == '(')
{
opstack.push(str[i]);
}
else if(isdigit(str[i] || str[i] == '*'))
{
tmp.clear();
while(isdigit(str[i]) || str[i] == '+')
{
tmp =+ str[i++];
}
}
}
}
BTNP ptr= new BTN;
ptr->flag = false;
ptr->value = value;
ptr->left = NULL;
ptr->right = NULL;
treeStack.push(ptr);
}
这是我造树的功能。我的教授已经把它写在黑板上了,我们不得不对它进行一些编辑,但我在BTNP部分不断出错。
stack<BTNP> treestack;
我一直在到处搜索示例代码,看看如何构建表达式树,但没有找到任何结果。即使我没有得到回应,一个链接也会很好。
我的错误:
BTNP is not identified.
while(i < str.length())
得到3个不同的错误,例如:
Error 3 error C2297: '<' : illegal, right operand has type 'unsigned int (__thiscall std::basic_string<_Elem,_Traits,_Alloc>::* )(void) throw() const'
Error 2 error C2446: '<' : no conversion from 'unsigned int (__thiscall std::basic_string<_Elem,_Traits,_Alloc>::* )(void) throw() const' to 'int'
Error 1 error C3867: 'std::basic_string<_Elem,_Traits,_Alloc>::length': function call missing argument list; use '&std::basic_string<_Elem,_Traits,_Alloc>::length' to create a pointer to member
4 IntelliSense: no instance of overloaded function "std::stack<_Ty, _Container>::push [with _Ty=BET::BTN, _Container=std::deque<BET::BTN, std::allocator<BET::BTN>>]" matches the argument list
argument types are: (BET::BTN *)
object type is: std::stack<BET::BTN, std::deque<BET::BTN, s
我得到的最后一个错误是treeStack.push(ptr(;
3 IntelliSense:重载函数"std::stack<_Ty,_Container>::push[with_Ty=BET::BTN,_Container=std::deque>]"的实例与参数列表不匹配参数类型为:(BET::BTN*(对象类型为:std::stack>>
错误2错误C2664:"void std::stack<_Ty>::push(BET::BTN&(':无法将参数1从"BET::BTN*"转换为"BET:&'
树的代码,或者我认为有些相关。。
struct BTN
{
bool flag;
char op;
double value;
BTN * left;
BTN * right;
BTN * BTNP;
};
// ...snip
int i = 0;
while(i < str.length)
{
// etc...
假设这段代码被复制并粘贴到问题中,那么str.length
后面的括号就不见了(尽管稍后在注释中已经包含了这些括号(。
因此,实际上并没有调用该函数,编译器抱怨(非常正确(它不知道如何告诉您成员函数是否大于int
。
将代码更改为str.length()
,这将有助于您进一步了解:-(
相关文章:
- 函数向量_指针有不同的原型,我可以构建一个吗
- libssh 的函数在构建 libssh 时无法在 Qt 和 cmake 错误中找到
- 在使用 GCC 4.8.5 构建的应用中对 cxx11 函数的未定义引用
- 有没有一种方法可以在linux中扫描已构建的ARM库中的函数
- 从函数的可变参数构建特定元组
- pair的两个构造函数几乎相同,为什么不生成构建错误?
- 仅在函数内部构建对象时EXC_BAD_ACCESS
- C++运行时构建嵌套函数
- 2个模板构造函数的组合构建与变异模板.如何
- 如何在类/类型中添加更多函数来构建 int、double、std::string 等
- 在函数呼叫时,请从异质初始化列表中构建元组
- 为链接列表构建迭代器类(错误:无匹配的构造函数以初始化)
- ITK中是否有表面构建函数,该函数返回一个容器管空间对象
- 使用可变参数模板构建函数参数
- 完美转发函数以构建函数列表类
- C++ 字符串,用于删除字符'b'并将字符'a'替换为两个'd'的构建函数
- 正在打印字符串构建函数的输出,但未返回预期结果
- 是否可以从XML文件动态构建函数声明
- 二进制表达式树c++构建函数
- 当从固定结构体中存储的对象构建函数时,c++ lambda构建静态函数返回意外值