DEV Community

Bhavana
Bhavana

Posted on

ALGORITHM of Infix to Postfix Conversion Using Stack.

Postfix expression: The expression of a b op. when an operator is followed for every pair of operands.

Infix expression: The expression of the from a op b. when an operator is in between every pair of operands

ALGORITHM

step1: First we should scan the infix expression from left to right

step2: If scanned character is an operand ,we should get the output.

step3:Else,pop all the operators in the stack which are greater than or equal to in precedence than that of the scanned operator to the stack

step4: If the scanned character is an ’ ( ', push it to the stack.

step5 : If the scanned character is an ‘)’,pop the stack an output it until it is encountered, and discard both the parenthesis.

step 6: Repeat steps 2-6 until infix expression is scanned.

step7: print the output

step 8: pop and output from the stack until it is not empty

Top comments (0)