Question
JAVA BST Implement remove, printReverse, and display method to display the tree structure Given________________ MyTree.java public class MyTree{ private TreeNode root; public MyTree(){ root=null; }
JAVA BST Implement remove, printReverse, and display method to display the tree structure
Given________________
MyTree.java
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 /* example:
5 1 8 -2 3 6 9 -3 -1 -4
*/
} 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() TreeNode.java (cannot be altered)public class TreeNode implements Comparable
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