English

Write an algorithm to evaluate a postfix expression.

Advertisements
Advertisements

Question

Write an algorithm to evaluate a postfix expression.

Short Answer
Advertisements

Solution

  1. Start.
  2. Create an empty stack.
  3. Scan the postfix expression from left to right.
  4. If the symbol is an operand, push it onto the stack.
  5. If the symbol is an operator, pop the required operands.
  6. Apply the operator in the correct order and push the result.
  7. After scanning all symbols, the top element is the result.
  8. Stop.
shaalaa.com
  Is there an error in this question or solution?
Chapter 6: Stacks & Queues in list - EXERCISE [Page 123]

APPEARS IN

CBSE Computer Science with Python [English] Class 12
Chapter 6 Stacks & Queues in list
EXERCISE | Q 18. | Page 123
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×