Usually used in the standard arithmetic expression, that is, "9+ (3-1) *3+10/2" is called infix expression. Because all the operational symbols are in the middle of two digits.
This infix expression "9+ (3-1) *3+10/2" into the suffix expression "9 3 1-3*+ 10 2/+", how to do it.
The rules are as follows:
1. Operand encountered: Direct output (added to suffix expression)
2. When the stack is empty, the operator is encountered, directly into the stack
3. Open parenthesis: Put it into stack
4. The closing parenthesis is encountered: Perform a stack operation and output the elements out of the stack until the pop-up stack is left parenthesis and the left parenthesis
does not output.
5. Encountered other operators: subtraction: Pop-up all priority greater than or equal to the operator of the top of the stack element, then the
operator into the stack ....
6. Finally, the stack of elements in sequence out of the stack, output.
For example a+b* (C (d+f))/e The process of the suffix expression is as follows:
1, read a, direct output a
2, read +, put in the stack
3, read B, direct output, at this time the stack has +, output AB
4, read *, because * priority is higher than +, into the stack, the stack has + * (right for the top of the stack)
5, read (, the highest priority, Encountered) only out, into the stack, the stack has + * (
6, read C, output ABC
7, read-, into the stack, the stack has + * (-
8, read (, into the stack, the stack has + * (
9, read D, output ABCD
10, read +, into the stack, the stack has + * ( -(+
11, read F, Output ABCDF
12, read), out stack +, output abcdf+, the stack has + * (-
13, read), out Stack-. Output abcdf+-, the stack has + *
14, read/, out stack *, into the stack/, output abcdf+-*, the stack has +/
15, read E, output abcdf+-*e
15, out stack/, Output abcdf+-*e/
16, out Stack +, output abcdf+-*e/+
so suffix expression is abcdf+-*e/+