Algorithm for Conversion Of An Expression From Infix to Postfix The stack contains only operators and left parentheses. If one operator is directly on top of another operator in the stack, the operator which is higher in the stack has higher precedence. No two operators have equal precedence. If the operators (such as + and -, or + and +) are said to have equal precedence, then precedence is determined by associativity rules. Since + and - are left-associative, the first one in an expression has priority. Since the operator ^ (meaning exponentiation) is right-associative, the last one in an expression has priority. The left parenthesis acts as an "insulator." An operator of lower precedence can be above an operator of higher precedence if there is a left parenthesis between them. Unary minus: we push the symbol ~ onto the stack, since otherwise, postfix expressions would be ambiguous. The unary minus is right-associative, meaning that --x means -(-x). Thus, ~ can be directly on top of another ~ in the stack. The following rules define the algorithm. 1. Print operands as they arrive. 2. If the stack is empty or contains a left parenthesis on top, push the incoming operator onto the stack. 3. If the incoming symbol is a left parenthesis, push it on the stack. 4. If the incoming symbol is a right parenthesis, pop the stack and print the operators until you see a left parenthesis. Discard the pair of parentheses. 5. If the incoming symbol has higher precedence than the top of the stack, push it on the stack. 6. If the incoming symbol has equal precedence with the top of the stack, use association. If the association is left to right, pop and print the top of the stack and then push the incoming operator. If the association is right to left, push the incoming operator. 7. If the incoming symbol has lower precedence than the symbol on the top of stack, pop the stack and print the top operator. Then test the incoming operator against the new top of stack. 8. At the end of the expression, pop and print all operators on the stack. (No parentheses should remain.)