|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.ObjectDataStructures.SearchTree<E>
E - the type of elements held in this treepublic class SearchTree<E extends java.lang.Comparable<? super E>>
A class implementing binary search trees for elements of type E.
Elements of type E must implement the Comparable interface in their defining class or in some superclass.
Trees are created empty using
SearchTree<Integer> t = new SearchTree<Integer>();Items can be added by
t.add(item);where
item is an element of type E .
Elements of type E can be removed by
t.remove(item);Trees can be traversed in order using an iteration, for example for an Integer tree:
for (Integer i : t) {
System.out.println(i);
}
| Constructor Summary | |
|---|---|
SearchTree()
Constructs an empty tree suitable for holding comparable elements of type E |
|
| Method Summary | |
|---|---|
void |
add(E item)
Adds an item into the tree, preserving the ordering property. |
boolean |
contains(E item)
Tests whether the item is present in the tree. |
java.util.Enumeration<E> |
elementsLevelOrder()
Provides an enumeration of the elements of the tree in level order. |
boolean |
isEmpty()
Tests if the tree is empty. |
java.util.Iterator<E> |
iterator()
Iterates over the items in the tree using the in-order sequence. |
int |
nrNodes()
Counts the number of nodes in the tree. |
void |
remove(E item)
Removes an item from the tree, preserving the ordering property. |
java.lang.String |
toString()
Converts the tree to a string. |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public SearchTree()
| Method Detail |
|---|
public boolean isEmpty()
public int nrNodes()
public boolean contains(E item)
item - the item to search for.
public void add(E item)
item - the item to add.public void remove(E item)
item - the item to remove.public java.util.Enumeration<E> elementsLevelOrder()
java.util.NoSuchElementException - if the nextElement method
is called when there is no next elementpublic java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E extends java.lang.Comparable<? super E>>java.util.NoSuchElementException - if the next method
is called when there is no next element
java.lang.IllegalStateException - if the next method has not
yet been called, or the remove method has already
been called after the last call to the next
method.public java.lang.String toString()
toString in class java.lang.Object
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||