|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--DataStructures.SearchTree
A class implementing binary search trees.
Trees are created using the empty and
add methods, for example:
SearchTree t = SearchTree.empty(); t = t.add(item);where
item belongs to a class implementing the
Comparable interface.
Elements can be removed by
t = t.remove(item);Trees can be traversed using an enumeration, for example:
for (Enumeration e = t.elementsInOrder(); e.hasMoreElements();) {
System.out.println(e.nextElement());
}
| Constructor Summary | |
SearchTree()
|
|
| Method Summary | |
abstract SearchTree |
add(java.lang.Comparable item)
Adds an item into the tree, preserving the ordering property. |
abstract boolean |
contains(java.lang.Comparable item)
Tests whether the item is present in the tree. |
abstract java.util.Enumeration |
elementsInOrder()
Provides an enumeration of the elements of the tree in order. |
abstract java.util.Enumeration |
elementsLevelOrder()
Provides an enumeration of the elements of the tree in level order. |
static SearchTree |
empty()
Returns an empty tree. |
abstract boolean |
isEmpty()
Tests if the tree is empty. |
abstract int |
nrNodes()
Counts the number of nodes in the tree. |
abstract SearchTree |
remove(java.lang.Comparable item)
Removes an item from the tree, preserving the ordering property. |
abstract java.lang.String |
toString()
Converts the tree to a string. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
public SearchTree()
| Method Detail |
public static SearchTree empty()
public abstract boolean isEmpty()
public abstract int nrNodes()
public abstract boolean contains(java.lang.Comparable item)
item - the item to search for.public abstract SearchTree add(java.lang.Comparable item)
item - the item to add.public abstract SearchTree remove(java.lang.Comparable item)
item - the item to remove.public abstract java.util.Enumeration elementsInOrder()
public abstract java.util.Enumeration elementsLevelOrder()
public abstract java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||