# Extends the Binary Tree

cybacatx
(Not rated)
(Not rated)
Chat

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.

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() {
}

public E findMax() {
}

public void removeMin() {
}

public void removeMax() {
}

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

• simpletree.java