Write a class for a bag of strings, where the strings are stored in a binary search
Question:
Write a class for a bag of strings, where the strings are stored in a binary search tree. In creating the binary search tree, you should use the string’s compareTo method, which is described on page 499. The tree itself should use the BTNode class from Figure 9.10.
Transcribed Image Text:
FIGURE 9.10 Specification and Implementation of the Generic Binary Tree Node Class Generic Class BTNode * public class BTNode
FIGURE 9.10 Specification and Implementation of the Generic Binary Tree Node Class Generic Class BTNode * public class BTNode from the package edu.colorado.nodes A BTNode provides a node for a binary tree with a reference to an E object as the data in each node. Limitations: Beyond Int. MAX_VALUE elements, treeSize is wrong. Specification Constructor for the BTNode public BTNode(E initialData, BTNode initiallLeft, BTNode initialRight) Initialize a node with specified initial data and links to children. Note that a reference to a child may be null, which indicates that there is no child. Parameters: initialData - the initial data of this new node initialleft and initialRight- references to the children of this new node Postcondition: This new node contains the specified data and links to its children. getData-getLeft-getRight public E getData( ) public BTNode getleft( ) public BTNode getRight( ) These are accessor methods to obtain this node's data or a reference to one of the children. Any of these objects may be null. A null reference to a child indicates that the child does not exist. getLeftmostData public E getleftmostData( ) Accessor method to get the data from the leftmost node of the tree below this node. Returns: The data from the deepest node that can be reached from this node following left links. getRightmostData public E getRightmostData( ) Accessor method to get the data from the rightmost node of the tree below this node. Returns: The data from the deepest node that can be reached from this node following right links.
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 83% (18 reviews)
Here is the class implementation for a bag of strings stored in a binary search tree public class BS...View the full answer
Answered By
Akshay Shete
I have extensive experience as a tutor, both online and in-person. I have worked with students of all ages and abilities, and am skilled at adapting my teaching style to meet the needs of each individual student. I have a strong background in a variety of subjects, including math, science, and English, and am able to break down complex concepts in a way that is easy for students to understand. In addition to my subject matter expertise, I am also a patient and supportive teacher, and am committed to helping my students succeed. Whether I am working with a struggling student who needs extra help to catch up, or an advanced student looking to get ahead, I am able to provide the guidance and support they need to reach their goals. Overall, my hands-on experience as a tutor has prepared me to be a confident and effective teacher, and I am excited to use my skills to help students succeed.
0.00
0 Reviews
10+ Question Solved
Related Book For
Question Posted:
Students also viewed these Computer science questions
-
Expand the class from Project 10 or 11 so that there is an extra method that produces a Java Iterator for the bag. Data from Project 10 Write a class for a bag of strings, where the strings are...
-
If you are familiar with Javas Comparable interface (Programming Project 11), then rewrite one of the sorting methods so that it sorts an array of Comparable objects. You may choose selectionsort,...
-
Java has a generic interface called Comparable. A class that implements the Comparable interface must have a method with this specification: compareTo public boolean compareTo(E obj) Compare this...
-
Partners have fiduciary obligations to each other. Explain what this means and give examples.
-
Weights of 100 M&Ms (use 12 classes with a class width of 0.017 and begin with a lower class boundary of 0.8375). a. Construct a histogram. b. Describe the general shape of the distribution, such as...
-
Most law enforcement officers go their whole career without ever having to discharge a firearm. When the situation calls for an officer to use deadly force many issues come up in very rapid...
-
Personal consumption in transportation. There has been phenomenal growth in the transportation sector of the economy over the past decade. The personal consumption expenditure figures (in billions of...
-
The following selected data pertain to the Argent Division for last year: Sales............... $1,000,000 Variable costs............ $624,000 Traceable fixed costs......... $100,000 Average invested...
-
When companies struggle with thin (or narrowing) margin, cost-cutting initiatives draw more attention from the managers. Even with robust economic growth, companies are often pressed to reduce their...
-
Is it appropriate to view firms primarily as economic entities?
-
An internal iterator for a bag is a collection of methods that allows a programmer to step through the elements of a bag one at a time. For example, we might have an internal iterator consisting of...
-
Using a heap, implement the priority queue ADT from Section 7.4. You can store the heap in arrays, similar to the solution to Self-Test Exercise 1. To have FIFO behavior for elements with equal...
-
Assuming that there is no transformation of mass to energy or vice versa, it is possible to write a continuity equation for mass. (a) If we use the continuity equation for charge as our model, what...
-
(a) Draw a simplified ray diagram showing the three principal rays for an object located inside the focal length of a converging lens, closer to the lens than to the focal point. (b) Is the image...
-
Power efficiency has become very important for modern processors, particularly for embedded systems. Create a version of gcc for two architectures that you have access to, such as x86, RISC-V,...
-
There is a movement toward wireless mobile computing using thin-client technology. Go to the Web and visit some of the ma jor computer vendors that are producing thin-client products such as handheld...
-
Draw a B-tree of order 4 and height 3 containing the fewest elements. Show an example of a split that would be applied by inserting the fewest number of elements.
-
Repeat Example 10-4, except calculate the diameter at the bottom of the column. Example 10-4 A distillation column is separating n-hexane from n-heptane using 1-in. ceramic Intalox saddles. The...
-
Simplify. (x 4 )(x 5 )/x 7
-
For the next several days, take notes on your listening performance during at least a half-dozen situations in class, during social activities, and at work, if applicable. Referring to the traits of...
-
Calculate (3.41796875 10 -3 6.34765625 10 -3 ) 1.05625 10 2 by hand, assuming each of the values are stored in the 16-bit half precision format described in Exercise 3.27 (and also described in...
-
Calculate 3.41796875 10 -3 (6.34765625 10 -3 1.05625 10 2 ) by hand, assuming each of the values are stored in the 16-bit half precision format described in Exercise 3.27 (and also described in...
-
Calculate 1.666015625 10 0 (1.9760 10 4 + -1.9744 10 4 ) by hand, assuming each of the values are stored in the 16-bit half precision format described in Exercise 3.27 (and also described in the...
-
thumbs up if correct A stock paying no dividends is priced at $154. Over the next 3-months you expect the stock torpeither be up 10% or down 10%. The risk-free rate is 1% per annum compounded...
-
Question 17 2 pts Activities between affiliated entities, such as a company and its management, must be disclosed in the financial statements of a corporation as O significant relationships O segment...
-
Marchetti Company, a U.S.-based importer of wines and spirits, placed an order with a French supplier for 1,000 cases of wine at a price of 200 euros per case. The total purchase price is 200,000...
Study smarter with the SolutionInn App