Steps to convert postfix expression to prefix
Scan the given postfix expression from left to right character by character.
If the character is an operand, push it into the stack.
But if the character is an operator, pop the top two values from stack.
Concatenate this operator with these two values (operator+2nd top value+1st top value) to get a new string.
Now push this resulting string back into the stack.
Repeat this process untill the end of postfix expression. Now the value in the stack is the desired prefix expression.
Conversion of Postfix to Prefix using Stack
No comments:
Post a Comment