Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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{ 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

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

Students also viewed these Databases questions

Question

Explain why O2-containing atmospheres kill some microbes.

Answered: 1 week ago