Data structures used to stack expressions into Reverse Polish Notation

A common sequence in an expression converted to a reverse Polish notation general algorithm is:
First you need to allocate two stacks, as a temporary storage operator stack S1 (including the end of a symbol), as an input a reverse Polish stack S2 (empty stack), the stack may be first placed Sl lowest priority operators # , note should end this type infix lowest priority of operators. You can specify other characters, not necessarily non-#. From the left end of the take-conjugated type character sequence carried out by the following steps:
(1) If the fetched character is an operand , a complete analysis of the operand, the operand stack directly into S2
(2) If the fetched character is the operator , then the operator stack with the top element S1, and if the operator precedence (not including the bracket operator) is larger than S1 stack stack operator precedence, then the S1 operator into the stack, otherwise, the operators S1 stack pop stack, the stack into the S2, S1 stack until the stack below the operator (not equal to) the priority of the operator, and finally sent to the operator S1 into the stack.
(3) If the fetched character is "(", directly into the top of the stack S1.
(4) If the fetched character is ")", the nearest distance S1 stack stack "(" between the operator, one by one out of the stack , the stack S2 is fed successively, then discard "(."
(5) Repeat steps 1-4 until all the input characters have been processed
(6) If the fetched character is "#", all operators will be within the stack S1 (not including the "#"), one by one out of the stack, the stack S2 is fed sequentially.
Completing the above steps, S2 stack is then reverse Polish notation output. But what should be done in reverse order processing S2. It can be calculated according to the calculation method of Reverse Polish Notation!
 
Excerpt from Baidu Encyclopedia
 

Guess you like

Origin www.cnblogs.com/zhanglehpu0419/p/11305727.html