Review Note

Last Update: 03/13/2024 10:56 AM

Current Deck: IIIT Nagpur::2nd Semester::5. Data Structures::L-17 Stack Applications-II

Published

Currently Published Content


Front
Infix to Postfix Conversion Algorithm
Back
     Infix to Postfix Conversion Algorithm
1.    Print the operand as they arrive.
2.    If the stack is empty or contains a left parenthesis on top, push the
      incoming operator on to the stack.
3.    If the incoming symbol is '(', push it on to the stack.
4.    If the incoming symbol is ')', pop the stack and print the operators until the
      left parenthesis is found.
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 lower precedence than the top of the stack,
      pop and print the top of the stack. Then test the incoming operator against
      the new top of the stack.
7.    If the incoming operator has the same precedence with the top of the
      stack then use the associativity rules.
      1. If the associativity is from left to right then pop and print the top of
            the stack then push the incoming operator.
      2. If the associativity is from right to left then push the incoming
            operator.
8.    At the end of the expression, pop and print all the operators of the stack.

No published tags.

Pending Suggestions


No pending suggestions for this note.