嗨,我可以寻求帮助吗?是否有中缀到后缀的公式?...我不知道如何转换它们并给出后缀表达式和后缀评估...例如这个 1*2(5+2 )-9/6。
问问题
152 次
2 回答
1
按照此过程从 转换infix
为postfix
:
Define a stack
Go through each character in the string
If it is between 0 to 9, append it to output string.
If it is left brace push to stack
If it is operator *+-/ then
If the stack is empty push it to the stack
If the stack is not empty then start a loop:
If the top of the stack has higher precedence
Then pop and append to output string
Else break
Push to the stack
If it is right brace then
While stack not empty and top not equal to left brace
Pop from stack and append to output string
Finally pop out the left brace.
If there is any input in the stack pop and append to the output string.
于 2012-08-17T08:46:19.857 回答
0
如果您想以不同的符号获得表达式,一种方法是使用二叉树并使用前/中/后遍历进行转换。
于 2012-08-17T08:46:33.770 回答