Binary Search Tree Interface


//----------------------------------------------------------------------------
// BSTInterface.java            by Dale/Joyce/Weems                  Chapter 7
//
// Interface for a class that implements a binary search tree (BST).
//
// The trees are unbounded and allow duplicate elements, but do not allow null
// elements. As a general precondition, null elements are not passed as
// arguments to any of the methods.
//
// The Collection interface requires the following methods:
//     boolean add(T element);
//     T get(T target);
//     boolean contains(T target);
//     boolean remove (T target);
//     boolean isFull();
//     boolean isEmpty();
//     int size();
//
//----------------------------------------------------------------------------
import java.util.Iterator;

public interface BSTInterface extends CollectionInterface, Iterable
{
  // Used to specify traversal order.
  public enum Traversal {Inorder, Preorder, Postorder};

  T min();
  // If this BST is empty, returns null;
  // otherwise returns the smallest element of the tree.

  T max();
  // If this BST is empty, returns null;
  // otherwise returns the largest element of the tree.

  public Iterator getIterator(Traversal orderType);
  // Creates and returns an Iterator providing a traversal of a "snapshot"
  // of the current tree in the order indicated by the argument.
}


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page