Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Implement the BinarySearchTree class. The BinarySearchTree class extends . Your assignment is to the BinaryTree class. implement all of the abstract methods of the
Implement the BinarySearchTree class. The BinarySearchTree class extends . Your assignment is to the BinaryTree class. implement all of the abstract methods of the BinaryTree class recursively. They are: insert iterator (non-recursive) remove search This is my assignment. I have coded it, but run into 1 error that I can't figure it out. I am going to include my code and a screenshot of the error in this post. CODE: import java.util.Iterator; import java.util.Random; import java.util.Vector; public class Main { public static void main(String[] args) { Binary Tree tree new BinarySearch Tree 0; Random rand; int num = args.length == 1? Integer.parseInt(args[0]): 1; long start, stop; rand = new Random(1); System.out.print("insert: "); start = System.current TimeMillis(); for (int i = 0; i < num; ++i) { tree.insert(rand.nextInt(num)); } stop = System.current TimeMillis(); System.out.println(stop - start); rand = new Random(1); System.out.print("search: "); for (int i = 0; i < num; ++i) { if (!tree.search(rand.nextInt (num))) { System.out.println("Fail"); } break; } for (Integer i : tree) { if (!tree.search(i)) { System.out.println("Fail"); break; } } } } } System.out.println("Pass"); tree.remove(num+1); rand = new Random(1); System.out.print("remove: "); start = System.current TimeMillis(); for (int i = 0; i < num; ++i) { tree.remove(rand.nextint(num)); } stop = System.current TimeMillis(); System.out.println(stop - start); rand = new Random(1); System.out.print("search: "); for (int i = 0; i < num; ++i) { if } (tree.search(rand.nextInt(num))) { System.out.println("Fail"); break; System.out.println("Pass"); System.out.println(tree.root == null); public abstract class Binary Tree implements Iterable { protected class Node { protected Node(T data) { this.data = data; } protected T data; protected Node left; protected Node right; } public abstract void insert(E data); public abstract void remove(E data); public abstract boolean search(E data); protected Node root; } import java.util.Iterator; public class BinarySearch Tree E extends Comparable } else { } curr.right = temp; break; } public Iterator iterator() { return null; } public void remove(E data) { if (root != null) { if (data.compareTo(root.data) == 0) { if (root.left == null || root.right == null) { root = root.left != null? root.left: root.right; } else { Node iop = findlOP(root); E temp = root.data; root data = iop.data; iop.data = temp; if (root.left== iop) { root.left=root.left.left; } else { Node curr=root.left; while (curr.right != iop) { curr = curr.right; } curr.right = curr.right.left; } else { Node curr = root; int cmp; while (true) { cmp = data.compare To(curr.data); if (cmp 0 && curr.right != null && data.compareTo(curr.right.data)!= 0) { curr = curr.right; } else { } break; if (cmp 0 && curr.right != null) { if (curr.right.left == null || curr.right.right == null) { curr.right = curr.right.left != null ? curr.right.left: curr.right.right; node.right=node.right.left; else { Node iop = findlOP(curr.right); E temp = curr.right.data; curr.right.data = iop.data; iop.data = temp; if (curr.right.left== iop) { curr.right.left= curr.right.left.left; } else { Node node= curr.right.left; while (node.right != iop) { node=node.right; } } node.right = node.right.left; public boolean search(E data) { Node curr = root; while (curr!= null) { if (data.compareTo(curr.data) == 0){ return true; } else if (data.compare To(curr.data) < 0) { } curr = curr.left; else { curr = curr.right; } return false; ERROR: > Console X Shell x 1 error exit status 1 + -d . > sh -c javac -classpath .:target/dependency/* $(find. -type f -name '*.java') ./BinaryTree.java:84: error: class, interface, enum, or record expected import java.util. Iterator; :
Step by Step Solution
★★★★★
3.44 Rating (151 Votes )
There are 3 Steps involved in it
Step: 1
The error message BinaryTreejava84 error class interface enum or record expected import javautilIter...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