Postfix expression calculator


What is Postfix expression?

An 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 –.

But in general expressions usually are in infix format.So, we have to convert them into postfix expression.For that you can use Infix to Postfix Converter .



How to evaluate Postfix expression?

1.First we read expression from left to right.So,During reading the expression from left to right, push the element in the stack if it is an operand.
2.If the current character is an operatorthen pop the two operands from the stack and then evaluate it.
3.Push back the result of the evaluation. Repeat it till the end of the expression.Checkout examples that are mention below in table

1) Postfix Expression: 54+
Answer: 9
2) Postfix Expression: 57+67+*
Answer: 156
3) Postfix Expression: 452*+5+
Answer: 19
3) Postfix Expression: 456*+
Answer: 34

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. But computer cannot differentiate the operators and parenthesis easily, that’s why postfix conversion is needed.Compilers or command editor in computer and some calculators also convert expression to postfix first and then solve those expression to evaluate answer for the same.