The infix expression "9 + (3-1) * 3 + 10/2" is converted to the suffix expression "9 3 1-3 * + 10 2/+"
How to convert an infix expression to a suffix expression:
1. operations encountered: Direct output (added to the suffix expression)
2. When the stack is empty, an operator is used to directly access the stack.
3. Left brackets: add them to the stack
4. Right parenthesis: Execute the stack exit Operation and output the elements of the stack until the left parenthesis is displayed and the left parenthesis is not output.
5. Other operators: subtraction, multiplication, division
6. Finally, the elements in the stack are output in sequence.
Implement 9 + (3-1) * 3 + 10/2, stack = empty
1.9 output expression = 9 stack = NULL
2. + inbound stack expression = 9 stack = +
3. (inbound stack expression = 9 stack = + (
4.3 output, expression = 9 3 stack = + (
5.-In stack, expression = 9 3 stack = + (-
6.1 output, expression = 9 3 1 stack = + (-
7) Compare the stack top expression = 9 3 1-stack = +
8. * inbound stack expression = 9 3 1-stack = + *
9. Output, expression = 9 3 1-3 stack = + *
10. + compare stack top expression = 9 3 1-3 * + stack = +
11.10 output expression = 9 3 1-3 * + 10 stack = +
12./inbound stack expression = 9 3 1-3 * + 10 stack = +/
13.2 output expression = 9 3 1-3 * + 10 2 stack = +/
14. Stack clearing expression = 9 3 1-3 * + 10 2/+ stack = NULL