Postfix to infix converter


What is postfix and infix expression?

An infix expression is expression which is used by us in day today life An infix expression is a single letter, or an operator, proceeded by one infix string and followed by another infix string. e.g. A,A + B,(A + B) + (C – D).So,in which we have operators between operands.And postfix expression (also called Reverse Polish Notation) is a single letter or an operator, preceded by two postfix strings. Every postfix string longer than a single variable contains first and second operands followed by an operator.e.g. A,A B +,A B + C D –



Conversion from postfix to infix expressions.

To convert postfix expression to infix expression, computers usually use the stack data structure. We start with scanning the equation from left to right and if the symbol is an operand then Push it onto the stack. or else, if the symbol is an operator then,
1. Pop the top 2 values from the stack.
2. Put the operator, with the values as arguments and form a string.
3. Push the resulted string back to stack.
4. If there is only one value in the stack That value in the stack is the desired infix string..Checkout examples that are mention below.

1) Postfix Expression: abc++
Infix Expression: (a + (b + c))

2) Postfix Expression: abc++
Infix Expression: (a + (b + c))

Applications

Infix expressions are readable and solvable by humans. We can easily distinguish the order of operators, and also can use the parenthesis to solve that part first during solving mathematical expressions. The computer cannot differentiate the operators and parenthesis easily, that’s why this conversion is needed , to convert the prefix/postfix expression into human-readable expression.