Infix to Postfix Conversion

Infix to Postfix Conversion

Infix to Postfix Conversion

 

Algorithm for Infix to Postfix Conversion

1.  scan infix expression from left to right

2.  if an operand is encountered add to P

3.  if an operator is found

         i) repeatedly pop the operator from stack which are having higher precedence than the operator found

         ii) add the new operator to stack

4.  if a right parenthesis found
           i) repeatedly pop the stack and add the poped operators to the expression until a left parenthesis is found.
           ii) remove the left parenthesis

5.   stop    

 Example for Infix to Postfix Conversion

Example : The Given Infix expression is ((A+B)/ C)


  Symbols Scanned  Stack              Postfix form P


          (                              (

          

           (                             ( (

      

           A                            ( (                      A


           +                             ( ( +                   A


           B                             ( ( +                   AB


           )                                ( (                     AB+


           /                                 ( (  /                  AB+


          C                                 ( (  /                 AB+C           


          )                                   ( (                    AB+C/