prefix to infix converter

What is prefix and infix expression?

A prefix expression is a expression in which first operator comes and proceded by strings. Every prefix string longer than a single variable contains first and second operands followed by an operator.e.g. A,+A B ,*A B ,+ * A B/ C D.

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.

Conversion from prefix to infix expressions.

First,Read the Prefix expression in reverse order (from right to left)
1.If the symbol is an operand, then push it into the Stack
2.But if the character is an operator, pop the top two values from stack.
3.Create a string by concatenating the two operands and the operator between them. string = (2nd top value+operator+1st top value)
4.And push the resultant string back to Stack Repeat the above steps until end of Prefix expression..Checkout examples that are mention below in table.And you can also check infix to prefix Converter and infix to postfix Converter .Checkout examples that are mention below.

1. Prefix Expression:+AB
Infix Expression: (A+B)

2. Prefix Expression: *CD
Infix Expression: (C*D)

3. Prefix Expression: *+AB+CD
Infix Expression: (A+B)*(C+D)


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.