Infix to prefix calculator

What is infix and prefix 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.

An expression is called the prefix expression if the operator appears in the expression before the operands. Simply of the form (operator operand1 operand2).e.g. *+AB-CD

Conversion from Infix to Prefix expressions.

To convert Infix to Prefix expression, computers usually use the stack data structure.
1. Reverse the infix expression.
2.Obtain the “nearly” postfix expression of the modified expression .
3. Reverse the postfix expression.
.Checkout examples that are mention below.

1) Infix Expression: (a+b)
Prefix Expression: +ab

2) Infix Expression: A*B+C/D
Prefix Expression: + * A B/ C D

3) Infix Expression: (a+b)*(c+d)
Prefix Expression: *+ab+cd


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 postfix/prefix conversion is needed.Compilers or command editor in computer and some calculators also convert expression to prefix/postfix first and then solve those expression to evaluate answer for the same.