Question
*Implement remove and printReverse method *Implement display method to display the tree structure public class MyTree{ private TreeNode root; public MyTree(){ root=null; } public void
*Implement remove and printReverse method *Implement display method to display the tree structure
public class MyTree{
private TreeNode root; public MyTree(){ root=null; } public void remove(int data){ //implement this method to remove a node with the same data value } public void printReverse(){ //implement this method to print data in descending order } public void display(){ //implement to display the tree structure } 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() given : TreeNode.java 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(); } }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started