-
Add the following methods to your Binary Search Tree class from the previous Lab Assignment AB30.1.
- public Object find(Comparable target)
- private Object findHelper(TreeNode root, Comparable target)
- public void delete(Comparable target)
- private TreeNode deleteHelper(TreeNode node, Comparable target)
-
However, you are required to code the two-child case for deletion as a mirror image of the solution described in Section B.7 of the lesson. Change the deleteTargetNode
method to deal with the two-child case as follows:
-
Position marker
to access the node with the smallest value in the right subtree. This is the leftmost node in the right subtree.
-
Copy the contents of the left child of marker
and set it as the current value.
-
Delete the smallest value from the left subtree. Reattach the left subtree to maintain an ordered tree.
Test your code and solve the following sequence of run output steps:
- Load the file from disk (file20.txt).
- Print the tree.
- Print the number of nodes in the tree.
- Search for Id values specified by your teacher. Print out the Id and Inv response in column form.
- Delete the Id values specified by your teacher.
- Print the tree again.
- Print the number of nodes in the tree.