English

Write an algorithm to convert infix to postfix.

Advertisements
Advertisements

Question

Write an algorithm to convert infix to postfix.

Short Answer
Advertisements

Solution

  1. Start.
  2. Create an empty operator stack and an empty output list.
  3. Scan the infix expression from left to right.
  4. Add operands directly to the output.
  5. Push a left parenthesis onto the stack.
  6. For a right parenthesis, pop operators to the output until the left parenthesis is found; then remove it.
  7. For an operator, pop operators having higher or equal precedence, then push the incoming operator.
  8. Pop all remaining operators to the output.
  9. 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 19. | Page 123
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×