Write a program called PostfixToInfix.java to solve the following problem. Write
ID: 3772801 • Letter: W
Question
Write a program called PostfixToInfix.java to solve the following problem.
Write a program to read in a postfix expression and output a corresponding infix expression. You may use any architecture and machinery developed and explained in class at length, as well as code from your solution to the last lab. Your output expression may have as many parethentheses as you decide are necessary for its unambigous evaluation without assuming anything about operator precedence. A postfix expression is defined as in the last lab, and all other details are defined as in class. Error messages for nonsense postfix expressions should be produced as defined in the last lab. You may not use any classes supplied with Java apart from those used in teaching this class. Your program should have behavior as illustrated by the following instance.
java PostfixToInfix
1 2 3 + *
1*(2+3)
Submit PostfixToInfix.java to moodle as your solution.
Explanation / Answer
import java.io.IOException; public class InToPost { private Stack theStack; private String input; private String output = ""; public InToPost(String in) { input = in; int stackSize = input.length(); theStack = new Stack(stackSize); } public String doTrans() { for (int j = 0; jRelated Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.