Part 1:
Implement the following:
1.
/**
*
* @param e
* @return the node that contains the parameter e and its parent node inside the
* NodeAndParent, or
* null if the e is not in the tree
*/
private NodeAndParent findNode(E e)
{
NodeAndParent nodeNparent = new NodeAndParent();
//add the code
return nodeNparent;
}
2. Modify the remove so it usesfindNode( E e )
instead of find() method and in the removal of nodes that have 1 child.
3. Modify the case of remove with 2 children using findNode( E e ) .
4. Modify the case of remove method with 2 children as follows:
Currently, w
hen the
node to be deleted is found, the existing loop with the 3 pointers takes 1 left and then keeps on going right until the first pointer hits null. Modify the loop to take 1 right instead, and then to keep on going left until the 1st pointer hits null. The BST property must be preserved after the removal. That is, the parent is greater that its left child and smaller that its right child.
Part 2:
(Add new methods in BST) Add the following new methods in BST.
/** Displays the nodes in a breadth-first traversal */
public void breadthFirstTraversal()
/** Returns the height of this binary tree */
public int height()
4.**25.3 (Implement inorder traversal without using recursion) Implement the inorder
method in BST using a stack instead of recursion. Write a test program that
prompts the user to enter 10 integers, stores them in a BST, and invokes the
inorder method to display the elements.
**25.6 (Find the leaves) Add a method in the BST class to return the number of the
leaves as follows:
/** Returns the number of leaf nodes */
public int getNumberOfLeaves()
**25.7 (Find the nonleaves) Add a method in the BST class to return the number of the
nonleaves as follows:
/** Returns the number of nonleaf nodes */
public int getNumberofNonLeaves()
**25.9 (Tree clone and equals) Implement the clone and equals methods in the
BST class. Two BST trees are equal if they contain the same elements. The
clone method returns an identical copy of a BST.