Professional Documents
Culture Documents
Conversion: Prefix To Postfix and Infix
Conversion: Prefix To Postfix and Infix
Conversion: Prefix To Postfix and Infix
PREFIX TO POSTFIX
AND INFIX
BY- RIYA GUPTA 20CSU269
a
b a+b
c c a+b*c
public static String convert(String str){
Stack<String> stack = new Stack<>();
But if the character is an operator, pop the top two values from stack.
Repeat this process untill the end of prefix expression. Now the value in
the stack is the desired postfix expression.
LET’S TAKE AN EXAMPLE…
PREFIX:
*+ab+cd dc+ba+*
a
c b ab+
d cd+ cd+ ab+ cd+*
public static String convert(String str){
Stack<String> stack = new Stack<>();