Homework 6 Assignment (due Tuesday 5/10)

Implement the methods indicated below. The hardest one to implement is the remove() method.

Submit your completed SimpleBinaryTree.java code to Blackboard ("Homework 6").


	/**
	 * Print the contents of the tree, in order, from "smallest" to "largest"
	 */
	public void printInOrder() {
		level =0;
		if( size == 0 ) // empty tree
			System.out.println("Empty");
		else
			// TODO: ask each Entry to print itself and its subtree
	}

	/**
	 * Print the contents of the tree, in reverse order, from "largest" to "smallest"
	 */
	public void printInReverseOrder() {
		level =0;
		if( size == 0 ) // empty tree
			System.out.println("Empty");
		else
			// TODO: ask each Entry to print itself and its subtree
	}
	
	/**
	 * print the "largest" element in the tree
	 */
	public void printLargestElement() {
		// TODO : complete, using a recursive method you implement in the Entry nested class
	}
	
	/**
	 * print the "smallest" element in the tree
	 */
	public void printSmallestElement() {
		// TODO : complete, using a recursive method you implement in the Entry nested class
	}
	
	/**
	 * print all the elements in the tree that are smaller than the argument
	 */
	public void printSmallerElements( E e ) {
		// TODO : complete, using a recursive method you implement in the Entry nested class
	}
	
	/**
	 * print all the elements in the tree that are larger than the argument
	 */
	public void printLargerElements( E e) {
		// TODO : complete, using a recursive method you implement in the Entry nested class
	}

	/* (non-Javadoc)
	 * @see java.util.Set#remove(java.lang.Object)
	 */
	public boolean remove(Object target) {
		if( target == null ) // don't allow null removal targets!
			throw new NullPointerException("Null argument to remove()");
		if( root == null )
			return false; // tree is empty; can't remove
		if( !root.contains( (E)o ) ) // tree does not contain the target; can't remove
			return false;
		
		return root.remove((E)o); 
	}