25.15 (Parent reference for
BST ) Redefine TreeNode by adding a reference to a node’s parent, as shown below:
BST.TreeNode<E>
#element: E
#left: TreeNode<E>
#right: TreeNode<E>
#parent: TreeNode<E>
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 :
/** Returns the node for the specified element.
* Returns null if the element is not in the tree. */
private TreeNode<E> 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<E> getPath(E e)
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.
Solution Will be completed Soon.
BST ) Redefine TreeNode by adding a reference to a node’s parent, as shown below:
BST.TreeNode<E>
#element: E
#left: TreeNode<E>
#right: TreeNode<E>
#parent: TreeNode<E>
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 :
/** Returns the node for the specified element.
* Returns null if the element is not in the tree. */
private TreeNode<E> 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<E> getPath(E e)
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.
Solution Will be completed Soon.
No comments:
Post a Comment