convert postfix to infix:
- Scan the given postfix expression from left to right character by character.
- If the character is an operand, push it into the stack.
- But if the character is an operator, pop the top two values from stack.
- Concatenate this operator with these two values (2nd top value+operator+1st top value) to get a new string.
- Now push this resulting string back into the stack.
- Repeat this process until the end of postfix expression. Now the value in the stack is the infix expression.
Postfix Expression Stack (Infix)
B + C * D – A
+ C * D – AB
C * D – (A+B)
* D – (A+B)C
D – ((A+B)*C)
– ((A+B)*C)D
(((A+B)*C)-D)
Comments
Leave a comment