Advertisements
Advertisements
Question
Write an algorithm to convert infix to postfix.
Short Answer
Advertisements
Solution
- Start.
- Create an empty operator stack and an empty output list.
- Scan the infix expression from left to right.
- Add operands directly to the output.
- Push a left parenthesis onto the stack.
- For a right parenthesis, pop operators to the output until the left parenthesis is found; then remove it.
- For an operator, pop operators having higher or equal precedence, then push the incoming operator.
- Pop all remaining operators to the output.
- Stop.
shaalaa.com
Is there an error in this question or solution?
