Question: Implement a class called ExpressionTree .The constructor to ExpressionTree will take in a String that contains a postfix expression. The operands will be integers and

 Implement a class called ExpressionTree .The constructor to ExpressionTree will take

Implement a class called ExpressionTree .The constructor to ExpressionTree will take in a String that contains a postfix expression. The operands will be integers and the binary operators will be restricted to +, and divide Individual tokens, that is the operands and operators, will be delimited by spaces. So for example 34 2-5* would mean (34-2) 5 Your constructor will run the stack based algorithm we discussed in class to build an expression tree ExpressionNodes will be a nested class within ExpressionTree. You may use any code posted on canvas or from the Weiss textbook as a starting point for this class. As a stack data structure, you can either use java.util.LinkedList, Once you have the ExpressionTree constructed you should provide the following four methods 1. public int evalO this method, when invoked on an expression tree object will return the integer value 2, public String postfix()-this method, when invoked on an expression tree object will return a String that 3. public String prefixO) this method, when invoked on an expression tree object will return a String that 4. public String infixO - this method, when invoked on an expression tree object will return a String that contains associated with evaluating the expression tree. It will need to call a private recursive method that takes in the root. contains the corresponding postfix expression. It will need to call a private recursive method that takes in the root. contains the corresponding prefix expression. It will need to call a private recursive method that takes in the root. the corresponding correct infix expression. Keep in mind that parenthesis will be needed (excessive parenthesis will be tolerated as long as it is correct). It will need to call a private recursive method that takes in the root. Write a class called Problem1.java that instantiates an expression tree on a hard coded string representing a postfix expression tree, and demonstrate all of the methods listed above

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!