Advertisements
Advertisements
Question
Write an algorithm to evaluate a postfix expression.
Short Answer
Advertisements
Solution
- Start.
- Create an empty stack.
- Scan the postfix expression from left to right.
- If the symbol is an operand, push it onto the stack.
- If the symbol is an operator, pop the required operands.
- Apply the operator in the correct order and push the result.
- After scanning all symbols, the top element is the result.
- Stop.
shaalaa.com
Is there an error in this question or solution?
