Saturday 12 October 2013

Infix to Postfix using Stack

Step1 : Push the delimiter “#” onto the stack.
Step2 : Read the characters one by one from the given infix expression
  1. If the character is an operand ,place it on to the output.
  2. If the character(ch) is equal to an operator or any opening symbol,then pop a character (pch)from the stack.If the stack priority of pch >= infix priority of ch ,then put pch in the output and push th ch into stack,if the condition didn‟t get satisfied then push pch and c into the stack.
  3. If the character is a closing symbol,pop all the operators from the stack till it encounters its corresponding opening symbol and place it on the output and discard both the opening and closing symbols.
Step3 : Repeat all the steps till # is encountered

No comments:

Post a Comment