Question: Codes give My Tree public class MyTree{ private TreeNode root; public MyTree(){ root=null; } public boolean isEmpty(){ //implement this method } public int size(){ //implement

Codes give
My Tree
public class MyTree{
private TreeNode root;
public MyTree(){
root=null;
}
public boolean isEmpty(){ //implement this method
}
public int size(){ //implement this method to return the number of nodes in the tree
return 0;
}
public void add(int data){ //implement this method to add the data to the tree
}
public void display(){ //implement this method to display the tree structure
}
public TeeeNode maxNode(){//implement this method to return the node which has the maximum value
}
public void inOrder(){ //visit left subtree, root, then right subtree
}
public void preOrder(){ //visit root, left subtree, then right subtree
}
public void postOrder(){// visit left subtree, right subtree, then root
}
public void printReverse(){ //implement this method to print the data in descending order
}
}
Node:
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();
}
}
 Codes give My Tree public class MyTree{ private TreeNode root; public

TIC . Create a java file named My Tree.java 2 Copy the entire code in the MyTree.txt and paste to your MyTree.java 3. Implement the required methods Once completed, use the TreeDriver.class to test your implementations. If all methods properly, the output should look like: reeDriver.class: Results 20 -mord inOrder 3 689 20 209863 638 20 8 6 20 9 reverse postOrder

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!