Implement the BinarySearchTree class. The BinarySearchTree class extends . Your assignment is to the BinaryTree class....
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
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<Integer> tree new BinarySearch Tree<Integer>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<E> implements Iterable<E> { protected class Node<T> { protected Node(T data) { this.data = data; } protected T data; protected Node<T> left; protected Node<T> right; } public abstract void insert(E data); public abstract void remove(E data); public abstract boolean search(E data); protected Node<E> root; } import java.util.Iterator; public class BinarySearch Tree E extends Comparable<? super E>> extends BinaryTree<E> { private Node<E> findlOP(Node<E> curr) { for (curr = curr.left; curr.right !=null; curr = curr.right); return curr; } public void insert(E data) { Node<E> temp = new Node <E>(data); if (root == null) { root = temp; } else { Node<E> curr = root; while (true) { if (data.compareTo(curr.data) <= 0) { if (curr.left != null) { curr = curr.left; } else { } curr.left = temp; break; } else { if (curr.right !=null) { curr = curr.right; } } else { } curr.right = temp; break; } public Iterator<E> 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 <E>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<E> curr=root.left; while (curr.right != iop) { curr = curr.right; } curr.right = curr.right.left; } else { Node<E> curr = root; int cmp; while (true) { cmp = data.compare To(curr.data); if (cmp <0 && curr.left != null && data.compareTo(curr.left.data) != 0) { curr = curr.left; } else if (cmp > 0 && curr.right != null && data.compareTo(curr.right.data)!= 0) { curr = curr.right; } else { } break; if (cmp <0 && curr.left != null){ if (curr.left.left == null || curr.left.right == null) { curr.left= curr.left.left != null ? curr.left.left: curr.left.right; } else { Node<E> iop=findlOP(curr.left); E temp = curr.left.data; curr.left.data = iop.data; iop.data = temp; if (curr.left.left== iop) { curr.left.left = curr.left.left.left; } else { Node<E> node = curr.left.left; while (node.right != iop) { node = node.right; } } } } else 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<E> 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<E> node= curr.right.left; while (node.right != iop) { node=node.right; } } node.right = node.right.left; public boolean search(E data) { Node<E> 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; : 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<Integer> tree new BinarySearch Tree<Integer>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<E> implements Iterable<E> { protected class Node<T> { protected Node(T data) { this.data = data; } protected T data; protected Node<T> left; protected Node<T> right; } public abstract void insert(E data); public abstract void remove(E data); public abstract boolean search(E data); protected Node<E> root; } import java.util.Iterator; public class BinarySearch Tree E extends Comparable<? super E>> extends BinaryTree<E> { private Node<E> findlOP(Node<E> curr) { for (curr = curr.left; curr.right !=null; curr = curr.right); return curr; } public void insert(E data) { Node<E> temp = new Node <E>(data); if (root == null) { root = temp; } else { Node<E> curr = root; while (true) { if (data.compareTo(curr.data) <= 0) { if (curr.left != null) { curr = curr.left; } else { } curr.left = temp; break; } else { if (curr.right !=null) { curr = curr.right; } } else { } curr.right = temp; break; } public Iterator<E> 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 <E>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<E> curr=root.left; while (curr.right != iop) { curr = curr.right; } curr.right = curr.right.left; } else { Node<E> curr = root; int cmp; while (true) { cmp = data.compare To(curr.data); if (cmp <0 && curr.left != null && data.compareTo(curr.left.data) != 0) { curr = curr.left; } else if (cmp > 0 && curr.right != null && data.compareTo(curr.right.data)!= 0) { curr = curr.right; } else { } break; if (cmp <0 && curr.left != null){ if (curr.left.left == null || curr.left.right == null) { curr.left= curr.left.left != null ? curr.left.left: curr.left.right; } else { Node<E> iop=findlOP(curr.left); E temp = curr.left.data; curr.left.data = iop.data; iop.data = temp; if (curr.left.left== iop) { curr.left.left = curr.left.left.left; } else { Node<E> node = curr.left.left; while (node.right != iop) { node = node.right; } } } } else 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<E> 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<E> node= curr.right.left; while (node.right != iop) { node=node.right; } } node.right = node.right.left; public boolean search(E data) { Node<E> 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; :
Expert Answer:
Answer rating: 100% (QA)
The error message BinaryTreejava84 error class interface enum or record expected import javautilIter... View the full answer
Related Book For
Building Java Programs A Back To Basics Approach
ISBN: 9780135471944
5th Edition
Authors: Stuart Reges, Marty Stepp
Posted Date:
Students also viewed these programming questions
-
Provide a solution using MATLAB to verify the formula of a centroid for the given example problem. Formula is provided. explain the use of how you used MATLAB to verify the formula of the attached...
-
0. Goals and Overview The goal of this assignment is to practice using recursion, and to use recursion to rewrite expressions. 1. Defining Expressions An expression consists of one or more...
-
I am working on a Linked List Set class that needs to adhere to the following regulations. And I need help. Do not change any files I provide. These files should remain as is, and you are not to add...
-
Tatum is a consultant at R.G. & Company (R.G.), a global consulting firm. She has enjoyed the past few years working at the company. As an ambitious person, she has been focusing on her long-term...
-
A large number of hydrogen atoms in Is states are placed in an external magnetic field that is in the + z-direction. Assume that the atoms are in thermal equilibrium at room temperature, T = 300K....
-
List all 10 possible SRSs of size n = 2, calculate the proportion of females for each sample, and display the sampling distribution of the sample proportion on a dotplot. The small population of 5...
-
The quality of Pinot Noir wine is thought to be related to the properties of clarity, aroma, body, flavor, and oakiness. Data for 38 wines are given in Table B. 11 . a. Fit a multiple linear...
-
The shareholders' equity portion of the balance sheet of Sessel's Department Stores, Inc., a large regional specialty retailer, is as follows: Disclosures elsewhere in Sessel's annual report revealed...
-
Standard Costing (Material and Labor Variances) ABC Company manufactures a chemical used for industrial maintenance. This chemical, which is sold by the drum. generally has a stable selling price....
-
The field is less sharply defined. There is heavier use of economics, decision sciences, and behavioral sciences. Identify the branch of accounting described in the quotation.
-
Instruction: In the table below identify the conjugate bases that are also weak acids. Acid name Strong acid hydroiodic acid perchloric acid hydrobromic acid hydrochloric acid sulfuric acid chloric...
-
Harry and Sally went to a large hardware store and told the salesperson they wanted the cheapest rotating clothesline in stock, provided it would bear a heavy load of washing. The salesperson assured...
-
Bill has leased a shop to Ahmed, but now wants him out because Janet will pay twice the rent Ahmed is paying. Bill starts annoying Ahmed. He disconnects the power, cuts the phone, and plays music...
-
Jack is allowed to store his car in a shed in Bert's large car-wrecker yard. Jack has an oral contract only and pays $20 a week. The shed is also used by Bert for storing old batteries and...
-
Equifax is one of the 'big three' credit agencies, sitting alongside Experian and TransUnion. In September 2017, the company became aware of a major security breach, which it said could affect around...
-
Does Samsung have a cost advantage (YES/NO), a differentiation advantage (YES/NO), or both a cost and differentiation advantage (YES/NO) over its rivals?
-
Choose the thermochemical equation that illustrates H 0 f forLi 2 SO 4 . H 2 S ( g) + 3O 2 (g) <=> 3H 2 O(g) + SO 2 (g) 8 Li 2 SO 4 (s) ----- > 16 Li(s) + S 8 (s,rhombic) + 16 O 2 Li 2 SO 4...
-
A condenser (heat exchanger) brings 1 kg/s water flow at 10 kPa quality 95% to saturated liquid at 10 kPa, as shown in Fig. P4.91. The cooling is done by lake water at 20C that returns to the lake at...
-
If our 8 Queens algorithm tried every possible square on the board for placing each queen, how many entries are there at the 8th and final level of the full tree? What does our algorithm do to avoid...
-
Write a method called monthApart that accepts four integer parameters, m1, d1, m2, and d2, representing two calendar dates. Each date consists of a month (1 through 12) and a day (1 through the...
-
Write a recursive method called dedup that takes a string as a parameter and that returns a new string obtained by replacing every sequence of repeated adjacent letters with just one of that letter....
-
Reconsider the data of Problem 31. Data from Problem 31 The following three investment opportunities are available. The returns for each investment for each year vary, but the first cost of each is...
-
The following three investment opportunities are available. The returns for each investment for each year vary, but the first cost of each is $20,000. Based on a future worth analysis, which...
-
Explain the concept of a control variable and the assumption necessary for a control variable to be effective.
Study smarter with the SolutionInn App