#include \n#include \n#include \n\nint getPrecedence(char op) {\n if (op == '+' || op == '-') {\n return 1;\n } else if (op == '*' || op == '/') {\n return 2;\n } else {\n return 0;\n }\n}\n\nstd::string infixToPostfix(const std::string& infix) {\n std::string postfix;\n std::stack operatorStack;\n\n for (char c : infix) {\n if (isalnum(c)) {\n postfix += c;\n } else if (c == '(') {\n operatorStack.push(c);\n } else if (c == ')') {\n while (!operatorStack.empty() && operatorStack.top() != '(') {\n postfix += operatorStack.top();\n operatorStack.pop();\n }\n operatorStack.pop(); // 弹出左括号\n } else {\n while (!operatorStack.empty() && getPrecedence(operatorStack.top()) >= getPrecedence(c)) {\n postfix += operatorStack.top();\n operatorStack.pop();\n }\n operatorStack.push(c);\n }\n }\n\n while (!operatorStack.empty()) {\n postfix += operatorStack.top();\n operatorStack.pop();\n }\n\n return postfix;\n}\n\nint main() {\n std::string infixExpression;\n std::cout << "请输入中缀表达式: ";\n std::cin >> infixExpression;\n\n std::string postfixExpression = infixToPostfix(infixExpression);\n std::cout << "后缀表达式为: " << postfixExpression << std::endl;\n\n return 0;\n}\n\n这个代码中的infixToPostfix函数接受一个中缀表达式作为参数,并返回对应的后缀表达式。它使用一个栈来保存运算符,并根据运算符的优先级决定何时将运算符加入到后缀表达式中。最后,需要将栈中剩余的运算符依次弹出并加入到后缀表达式中。\n\n示例输入和输出:\n\n\n请输入中缀表达式: (3+4)*5-6/2\n后缀表达式为: 34+5*62/-\n