1. Conversion of postfix into Prefix
Expression
Algorithm:
Step 1) Read the Postfix expression from left to right
Step 2) If the symbol is an operand, then push it onto the Stack
Step 3) If the symbol is an operator, then pop two operands from the
Stack
Step 4) Create a string by concatenating the two operands and the
operator before them.
Step 5) string = operator + operand2 + operand1
Step 6)And push the resultant string back to Stack
Step 7)Repeat the above steps until end of Prefix expression.
21. Conversion of Infix into Prefix
Expression
Step 1: Reverse the infix expression i.e A+B*C will become C*B+A.
Step 2: Obtain the postfix expression of the modified expression i.e CB*A+.
Step 3: Reverse the postfix expression. Hence in our example prefix is +A*BC.
Time complexity: O(n)