1. infix expression to postfix expression
Rule: (Stack implementation)
1) If the operand is encountered, we will output it directly.
2) If an operator is encountered, we put it on the stack and we put it in the stack when we encounter the opening parenthesis.
3) If a closing parenthesis is encountered, the stack element pops up and the output of the operator is ejected until an opening parenthesis is encountered. Note that the left parenthesis only pops up and does not output.
4) If any other operator is encountered, such as ("+", "*", "("), and so on, pops the element from the stack until it encounters an element that finds a lower priority (or the stack is empty) . After the elements are ejected, the operators encountered are pressed into the stack. there is a point to note that only when encountering ") "In case we just pop up" (", otherwise we will not pop up" (".
5) If we read the end of the input, all the elements in the stack are popped in turn.
2. Evaluation of suffix expressions
(1) build a stack s;
(2) Read the suffix expression from left to right, read the number to convert it to the value of the stack s, read the operator from the stack to pop up two numbers to Y and X, and then the "X operator Y" form the computer results, and then press the stack s;
(3) If the suffix expression is not read, repeat the above procedure, the final output stack at the top of the value is the end.
Application of stack: infix expression to suffix expression