Question: Java Language. For this lab assignment, you are required to implement the methods specified in the MyTree.txt file: 1. Create a java file named MyTree.java

Java Language.
For this lab assignment, you are required to implement the methods specified in the MyTree.txt file:
1. Create a java file named MyTree.java
and paste to your MyTree.java 3. Implement the required methods: -----
2. Copy the entire code in the MyTree.tx
t------------------------------------------------------------------
public void delete(int data){// implement this method
} public int height(){ //imjplement this method
od
} public MyTree balance(){ //implement this met h }
ted, use the TreeDriver.class to test your implementations. If you implemented all methods properly, the output should look like: TreeDriver.c
4. Once compl elass: Results height= 3 300 85 22 10 6 After deleting 300: height= 2 85 22 10 6
7
Test balancing method Tree before balancing: 9 8 6 5 4 3 2 1 After balancing: 9 8 7 6 5 4
2
3 2 1 Tree before balancing: 9 8 6 5 4 3 1 0 After balancing: 9 8 6 5 4 3 2
98
1 0 Tree before balancing: 98 78 56 45 9 9 1 0 After balancing: 78 56 45 9 9 1
0
Code given 
public class TreeNode implements Comparable{ private int data; private TreeNode left; private TreeNode right; public TreeNode(int data){ this.data=data; left=right=null; } public int getData(){ return data; } public TreeNode getLeft(){ return left; } public TreeNode getRight(){ return right; } public void setData(int data){ this.data = data; } public void setLeft(TreeNode left){ this.left = left; } public void setRight(TreeNode right){ this.right = right; } public int compareTo(TreeNode node){ return data-node.getData(); } } 
Code Given
import java.util.*; public class MyTree{ private TreeNode root; public MyTree(){ root=null; } public boolean isEmpty(){ return root==null;} public int size(){ return sizeHelper(root); } private int sizeHelper(TreeNode node){ if(node==null) return 0; else return 1+sizeHelper(node.getLeft())+sizeHelper(node.getRight()); } public boolean search(int data){ return searchHelper(root, data); } private boolean searchHelper(TreeNode node, int data){ if(node==null) return false; if(node.getData()==data) return true; else if(node.getData() 
Tree Given
Tree 1 2 3 4 5 6 7 8 9 End Tree 9 8 6 5 4 3 2 1 0 End Tree 78 9 56 98 9 0 1 45 End 

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!