Redefine TreeNode by adding a reference to a node?s parent, as shown below: Reimplement the insert and
Question:
Redefine TreeNode by adding a reference to a node?s parent, as shown below:
Reimplement the insert and delete methods in the BST class to update the parent for each node in the tree. Add the following new method in BST:
Write a test program that prompts the user to enter 10 integers, adds them to the tree, deletes the first integer from the tree, and displays the paths for all leaf nodes. Here is a sample run:
Transcribed Image Text:
BST.TreeNode
BST.TreeNode #element: E #left: TreeNode #right: TreeNode #parent: TreeNode /** Returns the node for the specified element. * Returns null if the element is not in the tree. */ private TreeNode getNode (E element) /** Returns true if the node for the element is a leaf */ private boolean isLeaf(E element) /** Returns the path of elements from the specified element * to the root in an array list. */ public ArrayList getPath(E e)
Fantastic news! We've Found the answer you've been seeking!
Step by Step Answer:
Answer rating: 40% (5 reviews)
Refer to Listing 252 253 254 255 257 from the Textbook Create the generic class TreeNode and extend the generic to Comparable Create the properties of the TreeNode class as given in the problem that i...View the full answer
Answered By
Muhammad Umair
I have done job as Embedded System Engineer for just four months but after it i have decided to open my own lab and to work on projects that i can launch my own product in market. I work on different softwares like Proteus, Mikroc to program Embedded Systems. My basic work is on Embedded Systems. I have skills in Autocad, Proteus, C++, C programming and i love to share these skills to other to enhance my knowledge too.
3.50+
1+ Reviews
10+ Question Solved
Related Book For
Introduction to Java Programming, Comprehensive Version
ISBN: 978-0133761313
10th Edition
Authors: Y. Daniel Liang
Question Posted:
Students also viewed these Computer science questions
-
Suppose that the TreeNode class defined in BST contains a reference to the node?s parent, as shown in Programming Exercise 25.15. Implement the AVLTree class to support this change. Write a test...
-
1. What is an advantage of a linked list over an array? A. Linked lists take up less space per element B. Linked lists can grow dynamically to hold individual new elements without copying existing...
-
For each B+-tree as shown below show the form of the tree after each of the following series of operations: a. Insert 9. b. Insert 10. c. Insert 8. d. Delete 23. e. Delete 19. Construct a B+-tree for...
-
Dixie Irwin is the department manager for Religious Books, a manufacturer of religious books that are sold through Internet companies. Irwins bonus is based on reducing production costs. Irwin has...
-
Let xn x be a convergent sequence in a normed linear space. Then ||xn|| ||x|| Furthermore the norm respects the linearity of the underlying space.
-
The following facts apply to the ABC Company in the year 20XX. 1. Stockholders invest $1,000,000. 2. The company buys land for $20,000 and a building for $380,000 in cash. 3. The company borrows...
-
Andrew Reitz established a trust in 2000, naming his sons, James and John, as sole beneficiaries and himself as trustee. Upon Andrews death, Hal Rachal Jr., the attorney who drafted the trust, became...
-
Three different plans for financing a $200,000,000 corporation are under consideration by its organizers. Under each of the following plans, the securities will be issued at their par or face amount,...
-
3 Eight students were asked to estimate the mass of a bag of sweets in grams. First they were asked to estimate the mass without touching the bag and then they were told to pick the bag up and...
-
Table 3.1 presents R&E Supplies' financial statements for the period 2014 through 2017, and Table 3.5 presents a pro forma financial forecast for 2018. Use the information in these tables to...
-
Write a program that prompts the user to enter a file name, then displays the frequency table of the characters in the file and displays the Huffman code for each character.
-
Revise BST in Listing 25.5, using a generic parameter and a Comparator for comparing objects. Define a new constructor with a Comparator as its argument as follows:BST(Comparator comparator) Listing...
-
The factor of safety for tipping of the concrete dam is defined as the ratio of the stabilizing moment about O due to the dams weight divided by the overturning moment about O due to the water...
-
Anne Investa is offered one of the following alternative cash flows: Alternative 1: $9,700 now. Alternative 2: $1,850 per year for the next 5 years. Alternative 3: $21,000 at the end of 8 years. If...
-
Draw schematic diagram to show what happens after the execution of the following instruction. a) LDS CX, [SP] (If after execution: DS= ABEOH, SS=D750H, SP =0000H) b) REP STOSB (If before execution:...
-
suppose the price elasticity of demand for movies is -1.5.if the price of movies increase by 20%.by what percent would you expect the quantity demanded to decrease?
-
A motor with 400 windings, area=0.15m and B=0.17 has a current of 0.5 A when it is stalled, not turning. What is the amplitude of the torque the motor produces? When the rad motor is turning at 10 ,...
-
Question 12b. As a trainer, what do you think your responsibilities are for each of the Seven Steps for Planning Assessment? [Step 1 has been completed for you as an example.]
-
Western Wind Energy Corp. is in the business of developing, owning, and operating wind- and solar energy-generating facilities. The company is headquartered in Vancouver and has assets for both solar...
-
Is it a breach of fiduciary duty for a director of a real estate investment trust (REIT) negotiating a joint venture on behalf of the REIT with another director for the development of a portfolio of...
-
Is the bucket-sort algorithm in-place? Why or why not?
-
Jonathan has a comparison-based sorting algorithm that sorts the first k elements of a sequence of size n in O(n) time. Give a big-Oh characterization of the biggest that k can be.
-
Of the n! possible inputs to a given comparison-based sorting algorithm, what is the absolute maximum number of inputs that could be correctly sorted with just n comparisons?
-
There are two components of leadership. The first is your own personal style and the second is how you choose to lead. Use the following checklist to evaluate your leadership style: What Kind of a...
-
Selected Realized Returns, 1926-2017 Average Return Standard Deviation Small-cap stocks 16.5% 31.7% Large-cap stocks 12.1 19.8 Long-term corporate bonds 6.4 8.3 Long-term government bonds 6.0 9.9...
-
1. What traits do you admire in leaders and professionals from your own experience? Why? 2. Identify your leadership strengths and weaknesses. How do you plan to address the areas that need...
Study smarter with the SolutionInn App