任何包含(如(5 + 6)运行时错误的表达式都不知道为什么......我追踪了很多程序但是找不到错误...我的代码:< / p>
int main() {
string infix, temp = "";
cin >> infix;
stack<char> S;
for (int i = 0; i < infix.length(); i++){
if (infix[i] == '+' || infix[i] == '-' || infix[i] == '*' || infix[i] == '/'){
if (!S.empty() && priority(S.top()) <= priority(infix[i])){
while (!S.empty()){
temp += S.top();
S.pop();
}
}
S.push(infix[i]);
}
else if (infix[i] == '('){
S.push(infix[i]);
}
else if (infix[i] == ')'){
while (!S.empty() && S.top() != '('){
temp += S.top();
S.pop();
}
S.pop();
}
else
temp += infix[i];
}
while (!S.empty()){
temp += S.top();
S.pop();
}
cout << temp << endl;
}
提前感谢:)