The SimpleTree class shown below extends the BinaryTree class that was given out as part of SampleCode#7 and SampleCode#8, and as part of SampleCode #10. You are to write four methods for the SimpleTree class shown below called findMin(), findMax(), removeMin() and removeMax().

The methods are already in the SimpleTree class, but they do not do anything yet. The findMin() and findMax() methods should return the smallest or largest node value (respectively) as determined by the compareTo() method. And the removeMin() and removeMax() methods should remove the smallest or largest node value (respectively).

Note that the BinaryTree class implements a Binary Search Tree.

SampleCode10: https://drive.google.com/file/d/0BwHPwkI43NCycXNGenRuLTFST28/edit?usp=sharing

Answer: 

public class SimpleTree<E extends Comparable<E>> extends BinaryTree<E> {
public SimpleTree() {
super();
}

public SimpleTree(E element, SimpleTree<E> left, SimpleTree<E> right) {
root = createNewNode(element);
root.left = (left == null) ? null : left.getRoot();
root.right = (right == null) ? null : right.getRoot();
}

public E findMin() {
// Your code goes here
}

public E findMax() {
// Your code goes here
}

public void removeMin() {
// Your code goes here
}

public void removeMax() {
// Your code goes here
}

public E getRootElement() {
return (root == null) ? null : root.element;
}

public SimpleTree<E> getLeftNode() {
return getTreeNode(root.left);
}

public SimpleTree<E> getRightNode() {
return getTreeNode(root.right);
}

private SimpleTree<E> getTreeNode(TreeNode<E> node) {
if (node == null) return null;
return(new SimpleTree<E>(node.element,
getTreeNode(node.left),getTreeNode(node.right)));
}
}

    • 7 years ago
    100% Quality Work A+ Tutorial Guaranteed Work for you use as Guide
    NOT RATED

    Purchase the answer to view it

    blurred-text
    • attachment
      simpletree.java