Java Reference
In-Depth Information
The operations.
In addition to the common operations of a tree, as given in the interface
TreeInterface
, a binary search tree has basic database operations that search, retrieve, add,
remove, and traverse its entries. We can design an interface for a binary search tree, as well as for
other search trees that you will see in Chapter 27. Listing 25-1 provides such an interface.
LISTING 25-1
An interface for a search tree
package
TreePackage;
import
java.util.Iterator;
public interface
SearchTreeInterface<T
extends
Comparable<?
super
T>>
extends
TreeInterface<T>
{
/** Searches for a specific entry in this tree.
@param entry an object to be found
@return true if the object was found in the tree */
public boolean
contains(T entry);
/** Retrieves a specific entry in this tree.
@param entry an object to be found
@return either the object that was found in the tree or
null if no such object exists */
public
T getEntry(T entry);
/** Adds a new entry to this tree.
If the entry matches an object that exists in the tree
already, replaces the object with the new entry.
@param newEntry an object to be added to the tree
@return either null if newEntry was not in the tree already, or
an existing entry that matched the parameter newEntry
and has been replaced in the tree */
public
T add(T newEntry);
/** Removes a specific entry from this tree.
@param entry an object to be removed
@return either the object that was removed from the tree or
null if no such object exists */
public
T remove(T entry);
/** Creates an iterator that traverses all entries in this tree.
@return an iterator that provides sequential and ordered access
to the entries in the tree */
public
Iterator<T> getInorderIterator();
}
// end SearchTreeInterface