![]() |
VOOZH | about |
Given a Prefix expression, convert it into a Postfix expression. A Prefix expression places the operator before the operands (operator operand1 operand2), for example *+AB-CD is represented as (A + B) * (C − D). A Postfix expression places the operator after the operands (operand1 operand2 operator), for example AB+CD-* is represented as (A + B) * (C − D).
Example:
Input : Prefix : *+AB-CD
Output : AB+CD-*
Explanation : Prefix to Infix : (A+B) * (C-D)
Infix to Postfix : AB+CD-*
Input : Prefix : *-A/BC-/AKL
Output : ABC/-AK/L-*
Explanation : Prefix to Infix : (A-(B/C))*((A/K)-L)
Infix to Postfix : ABC/-AK/L-*
The idea is process from right to left so that we first see operands. We store operands in a stack. When an operator is found, the two most recent operands on the stack belong to it. Placing the operator after these operands forms the correct postfix expression
ABC/-AK/L-*