我是一名学生,我的课程分为三个部分,但最后一部分是我遇到麻烦的地方,我找不到办法解决它,它告诉我:
无效的用户定义从'char'转换为'const string& {又名 const std :: basic_string&}'[-fpermissive] while(!st.empty()&& st.top()!='('&& hasHigherPrecedence(st.top(),EXPR [I])){
我的代码:
string StacksAndQueues::convertInfixToPostfix(const string &expr) {
stack<char> st;
int n = expr.length();
string res = "";
for(int i = 0;i<n;i++){
if(expr[i] == '0' || expr[i] == '1' || expr[i] == '2' || expr[i] == '3' || expr[i] == '4' || expr[i] == '5' || expr[i] == '6' ||
expr[i] == '7' || expr[i] == '8' || expr[i] == '9'){
res = res + expr[i];
}else if(expr[i] == '+' || expr[i] == '-' || expr[i] == '*' || expr[i] == '/'){
while(!st.empty() && st.top() != '(' && hasHigherPrecedence(st.top(),expr[i])){
res = res + st.top();
st.pop();
}
st.push(expr[i]);
}
else if (expr[i] == '(')
{
st.push(expr[i]);
}
else if(expr[i] == ')')
{
while(!st.empty() && st.top() != '(') {
res = res + st.top();
st.pop();
}
st.pop();
}
}
while(!st.empty()) {
res = res + st.top();
st.pop();
}
return res;
}
bool StacksAndQueues::hasHigherPrecedence(const string &stackTop, const string &op) {
return !((stackTop == string("+") || stackTop == string("-")) &&
(op == string("*") || op == string("/")));
}