Question: I need a little help answering this question! This is the code for expression tree which needs to be implemented in order to solve this

I need a little help answering this question!

I need a little help answering this question! This is the code

This is the code for expression tree which needs to be implemented in order to solve this problem

import javax.swing.JOptionPane;

import java.util.*; import java.io.*;

public class ExpressionTree { private Node root;

public ExpressionTree (){ root = null; }

private ExpressionTree (Node r){ root = r; }

public ExpressionTree (String data, ExpressionTree leftT, ExpressionTree rightT){ root = new Node(data); if (leftT!=null) root.left = leftT.root; else root.left = null; if (rightT != null) root.right = rightT.root; else root.right = null; }

private static class Node { private E data; private Node left; private Node right;

private Node(E item){ data = item; left = null; right = null; }

private Node(E item, Node refLeft, Node refRight){ data = item; left = refLeft; right = refRight; }

} //end of private class }

1. Implement the class ExpressionTree to support the execution of the following program public class ExpTest i public static void main(String args[) Expres 10nTree a = new ExpressionTree (); a.initialization); System.out.println (a) System.out.println(a.cal()); When the input of the expression is "3 * ( 2 + 4 )-4 / 2 " the print out will be: JGRASP exec: java Exprest null null null null null null null null null null 0.20000000000000018 JGRASP: operation complete You can also test the program with the expression "9/3* (2 * 3 +4-2 * 3) / 2 - 4 / 2." We assume that the number is always double type and contains the decimal part. As required, you need to realize the input of an infix expression inside of the method "initialization," the display of the entire tree in the infix travel manner in "toString," and the calculation of the entire tree with the method "cal." 1. Implement the class ExpressionTree to support the execution of the following program public class ExpTest i public static void main(String args[) Expres 10nTree a = new ExpressionTree (); a.initialization); System.out.println (a) System.out.println(a.cal()); When the input of the expression is "3 * ( 2 + 4 )-4 / 2 " the print out will be: JGRASP exec: java Exprest null null null null null null null null null null 0.20000000000000018 JGRASP: operation complete You can also test the program with the expression "9/3* (2 * 3 +4-2 * 3) / 2 - 4 / 2." We assume that the number is always double type and contains the decimal part. As required, you need to realize the input of an infix expression inside of the method "initialization," the display of the entire tree in the infix travel manner in "toString," and the calculation of the entire tree with the method "cal

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!