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
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:
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)
Step by Step Solution
3.31 Rating (160 Votes )
There are 3 Steps involved in it
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 full answer
Get step-by-step solutions from verified subject matter experts
