Design and write a complete test program to test if the BST class in Listing 25.4 meets
Question:
Design and write a complete test program to test if the BST class in Listing 25.4 meets all requirements.
Data from Listing 25.4
Transcribed Image Text:
1 publ1c class BST
1 publ1c class BST 1mplements Tree { protected TreeNode root: protected 1nt size = 0: protected java.util.Comparator c: 4 1** Create a default BST with a natural order comparator */ publ1c BST () { this.c = (e1, e2) -> ((Comparable)e1).compareTo (e2): 6 7 8 10 /** Create a BST with a specified comparator */ publ1c BST (java.util.Comparator c) { 11 12 13 this.c c: 14 15 ** Create a binary tree from an array of objects */ publ1c BST (E[] objects) { this.c = (et, e2) -> ((Comparable) e1).compareTo (e2): for (1nt i = 0; i< objects.length: i++) add (objects[i]): } 16 17 18 19 20 21 22 e0verride /** Return true if the element is in the tree / publ1c boolean search(E e) { TreeNode current = root: // Start from the root 23 24 25 26 wh1le (current != nul1) { 1f (c.compare (e. current.element) < 0) { current = current.left: 27 28 29 30 else 1f (c.compare (e. current.element) > 0) { current = current.right: 31 32 33 else // element matches current.element return true: // Element is found 34 35 36 37 38 return false: 39 40 eOverride /** Insert element e into the binary tree * Return true if the element is inserted successfully */ pub11c boolean insert(E e) { 1f (root == nul1) root = createNewNode (e): I1 Create a new root else { Il Locate the parent node TreeNode parent = nul1; 41 42 43 44 45 46 47 48 49 TreeNode current = root: wh1le (current != nul1) 1f (c.compare(e, current.element) < 0) { parent = current; current = current.left: 50 51 52 53 54 else 1f (c.compare (e, current.element) > 0) { parent = current: current = current.right; 55 56 57 58 59 else
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 57% (7 reviews)
public class Exercise2512 private BST tree new BST public Exer...View the full answer
Answered By
David Ngaruiya
i am a smart worker who concentrates on the content according to my clients' specifications and requirements.
4.50+
7+ Reviews
19+ Question Solved
Related Book For
Introduction To Java Programming And Data Structures Comprehensive Version
ISBN: 9780136520238
12th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Design and write a complete test program to test if the MyArrayList class in Listing 24.2 meets all requirements. Data from Listing 24.2 1 publ1c class MyArrayList 1mplementS MyList { publ1c stat 1c...
-
Design and write a complete test program to test if the MyLinkedList class in Listing 24.5 meets all requirements. Data from Listing 24.5 1 publ1c class MyLinkedList 1mplements MyList private Node...
-
Design and write a complete test program to test if the MyArrayList class in Listing 24.3 meets all requirements. Listing 1 public class MyArrayList extends MyAbstractList { public static final int...
-
Write a check (Figure 4 - 42) dated June 13, 20XX, to Byron Johnson in the amount of $296.83 for a washing machine, Complete the check stub. Figure 4 - 42 456 456 Amount To For KRA, INC 2596 Jason...
-
Suppose that the time in between customers at a store are independent Exponential random variables, with an average of 2 minutes between consecutive customers. Let X be the time until the 3rd...
-
Last year's freshman class at Big State University totaled 5,324 students. Of those, 1,254 received a merit scholarship to help offset tuition costs their freshman year (although the amount varied...
-
The wreck of the S.S. Central America waited 130 years at the bottom of the ocean for someone to come along and claim its trove of gold. Thomas G. Thompson, funded by a multitude of investors, was...
-
Gore Range Carpet Cleaning is a small, family-owned business operating out of Eagle-Vail, Colorado. For its services, the company has always charged a flat fee per hundred square feet of carpet...
-
Let G = (V,E) be a simple graph with |V| 2. The complement graph G of G is the simple graph whose vertex set is V and whose edge set consists of all the edges that have as endpoints nonadjacent...
-
Refer to Exercise 13-25. Data From Exercise 13-25 Methuen Corporation makes a special-purpose machine, D4H, used in the textile industry. Methuen has designed the D4H machine for 2020 to be distinct...
-
Define a new class named BSTWithNumberOfNonLeaves that extends BST with the following methods: /** Return the number of nonleaf nodes */ public int getNumberofNonLeaves() Use...
-
Write a program that prompts the user to enter a file name, then displays the frequency table of the characters in the file and the Huffman code for each character.
-
Integrate the given function around the unit circle. (z 2 sin z)/(4z - 1)
-
Coaching Vs. Mentoring: 1. What core assumption underpins the coaching relationship? 2. What is the ultimate aim of coaching? 3. Which is not a good reason for an organization to support coaching? ...
-
What struck you mosteither most powerfully resonated with you or didn't resonate with youfrom the Not Just a Game video? Why? When Zirin makes the argument that sports are "political," he certainly...
-
In this exercise, you will compare your monthly outlays to your net income or take-home pay. It is important to spend purposefully, save strategically, invest carefully and give wisely. You want to...
-
Let A = 0 0 -1 0 1 4 0 0 -1 0 1 0 0 0 0 - -1 a) Show that de, (x) = x - 4 and de (x) = (x + 1). b) Find a vector u with du(x) = (x 4) (x + 1). c) Show that m(x) = (x 4)(x + 1). - d) Find RCF(A) and...
-
Discussion Forum 2 Topic: Our focus this week is on community change as part of our professional practice and our role in this change. Required Text(s): Homan, M.S. (2016). Promoting Community...
-
How would the volume of 1.00 cm3 of aluminum on Earth change if it were placed in a vacuum chamber and the pressure changed to that of the Moon (less than 109 Pa)?
-
In your audit of Garza Company, you find that a physical inventory on December 31, 2012, showed merchandise with a cost of $441,000 was on hand at that date. You also discover the following items...
-
Write a program that obtains the execution time of selection sort, bubble sort, merge sort, quick sort, heap sort, and radix sort for input size 50,000, 100,000, 150,000, 200,000, 250,000, and...
-
Write a program that randomly generates 1,000,000 integers and sorts them using radix sort.
-
Implement the clone and equals method in the Heap class.
-
Discuss the evolution of accounting theory and its significance in the contemporary business environment. Provide examples to illustrate how historical events and changing economic landscapes have...
-
( a ) Determine the capitalised cost at 3 . 5 % interest of a manufacturing plant with an initial cost of 1 , 7 5 0 , 0 0 0 and annual operating and maintenance costs of 2 8 , 0 0 0 ( payable at...
-
This is really an odd situation, said Jim Carter, general manager of Highland Publishing Company. We get most of the jobs we bid on that require a lot of press time in the Printing Department, yet...
Study smarter with the SolutionInn App