|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectstructure.AbstractStructure<ELTTYPE>
structure.BinarySearchTree<ELTTYPE>
structure.SplayTree<ELTTYPE>
public class SplayTree<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
An implementation of binary search trees, based on a splay operation by Tarjan et al. An extension of the binary search tree class that decreases the likelyhood of a binary tree becomming degenerate. Example usage:
To create a splay tree containing the months of the year and to print out this tree as it grows we could use the following.
public static void main(String[] argv){
SplayTree test = new SplayTree();
//declare an array of months
String[] months = new String[]{"March", "May", "November", "August",
"April", "January", "December", "July",
"February", "June", "October", "September"};
//add the months to the tree and print out the tree as it grows
for(int i=0; i < months.length; i++){
test.add(months[i]);
System.out.println("Adding: " + months[i] + "\n" +test.BinarySearchTree.treeString());
}
}
| Constructor Summary | |
|---|---|
SplayTree()
Construct an empty search tree. |
|
SplayTree(java.util.Comparator<ELTTYPE> alternateOrder)
Construct an empty search tree. |
|
| Method Summary | |
|---|---|
void |
add(ELTTYPE val)
Add a value to the splay tree. |
boolean |
contains(ELTTYPE val)
Determine if a particular value is within the search tree. |
ELTTYPE |
get(ELTTYPE val)
Fetch a reference to the comparable value in the tree. |
java.util.Iterator<ELTTYPE> |
iterator()
Construct an inorder traversal of the elements in the splay tree. |
ELTTYPE |
remove(ELTTYPE val)
Remove a comparable value from the tree. |
java.lang.String |
toString()
Construct a string that represents the splay tree. |
| Methods inherited from class structure.BinarySearchTree |
|---|
clear, hashCode, isEmpty, size, treeString |
| Methods inherited from class structure.AbstractStructure |
|---|
elements, values |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface structure.Structure |
|---|
clear, elements, isEmpty, size, values |
| Constructor Detail |
|---|
public SplayTree()
public SplayTree(java.util.Comparator<ELTTYPE> alternateOrder)
alternateOrder - the ordering imposed on the values inserted| Method Detail |
|---|
public void add(ELTTYPE val)
add in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>add in class BinarySearchTree<ELTTYPE extends java.lang.Comparable<ELTTYPE>>val - The value to be xadded.public boolean contains(ELTTYPE val)
contains in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>contains in class BinarySearchTree<ELTTYPE extends java.lang.Comparable<ELTTYPE>>val - The comparable value to be found.
public ELTTYPE get(ELTTYPE val)
get in class BinarySearchTree<ELTTYPE extends java.lang.Comparable<ELTTYPE>>val - The value to be sought in tree.
public ELTTYPE remove(ELTTYPE val)
remove in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>remove in class BinarySearchTree<ELTTYPE extends java.lang.Comparable<ELTTYPE>>val - The value to be removed.
public java.util.Iterator<ELTTYPE> iterator()
iterator in interface java.lang.Iterable<ELTTYPE extends java.lang.Comparable<ELTTYPE>>iterator in interface Structure<ELTTYPE extends java.lang.Comparable<ELTTYPE>>iterator in class BinarySearchTree<ELTTYPE extends java.lang.Comparable<ELTTYPE>>AbstractIterator,
Iterator,
Enumeration,
Structure.elements()public java.lang.String toString()
toString in class BinarySearchTree<ELTTYPE extends java.lang.Comparable<ELTTYPE>>
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||