Wednesday, 4 January 2017

Alogorithm of Infix to Postfix Conversion

Alogorithm of Infix to Postfix Conversion

1.Scan the Infix Expression from left to right character by character.

2.If scan charter is an operand then store it into Postfix(Display it on console).

3.If character is an opening bracket[ ( ] then push it into the stack.

4.If character is an operator and if the stack is empty push it into the stack

5.If the charter is an operator and the stack is non-empty then find incoming character (scan charter). Find the InStackPriority of the operator of top of stack and compare from ICP(Incoming Priority) with ISP(In Stack Priority).
 If
ISP is greater than ISP then push operator on stack
Else
pop one operator at a time at a stack and store it in Postfix array till ICP become smaller than ISP.
push scan charcter (oprator)on to the stack.

6.If a scan charter is a closing bracket[ ( ] pop all the operator on the stack still opening bracket is encountered discard both the bracket.

7.Repeate from step 2 to step 6 until scanning of expression from left to right.

8.Check if the stack is empty or not if the stack is not empty then pop all the operator and store it in Postfix array.   

9.Stop