-
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 the following Id values:
100 184 12345 15320 16000 19967 23456
Print out the Id and Inv response in column form.
Delete the following Id values:
18618 184 150 20000 14088 1400 18465
Print the tree again.
Print the number of nodes in the tree.