Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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!

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems An Application Oriented Approach Complete Version

Authors: Michael Kifer, Arthur Bernstein, Richard Lewis

2nd Edition

0321268458, 978-0321268457

More Books

Students also viewed these Databases questions

Question

Solve the given quadratic equations by factoring. x 2 + 3x 10 = 0

Answered: 1 week ago

Question

Differentiate tan(7x+9x-2.5)

Answered: 1 week ago

Question

Explain the sources of recruitment.

Answered: 1 week ago

Question

Differentiate sin(5x+2)

Answered: 1 week ago

Question

Compute the derivative f(x)=1/ax+bx

Answered: 1 week ago

Question

Describe how to train managers to coach employees. page 404

Answered: 1 week ago

Question

Discuss the steps in the development planning process. page 381

Answered: 1 week ago