|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectstructure5.AbstractStructure<E>
structure5.BinarySearchTree<E>
structure5.SplayTree<E>
public class SplayTree<E extends Comparable<E>>
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 = newSplayTree()
; //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(Comparator<E> alternateOrder)
Construct an empty search tree. |
Method Summary | |
---|---|
void |
add(E val)
Add a value to the splay tree. |
boolean |
contains(E val)
Determine if a particular value is within the search tree. |
E |
get(E val)
Fetch a reference to the comparable value in the tree. |
Iterator<E> |
iterator()
Construct an inorder traversal of the elements in the splay tree. |
E |
remove(E val)
Remove a comparable value from the tree. |
String |
toString()
Construct a string that represents the splay tree. |
Methods inherited from class structure5.BinarySearchTree |
---|
clear, hashCode, isEmpty, size, treeString |
Methods inherited from class structure5.AbstractStructure |
---|
elements, values |
Methods inherited from class java.lang.Object |
---|
equals, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface structure5.Structure |
---|
clear, elements, isEmpty, size, values |
Constructor Detail |
---|
public SplayTree()
public SplayTree(Comparator<E> alternateOrder)
alternateOrder
- the ordering imposed on the values insertedMethod Detail |
---|
public void add(E val)
add
in interface Structure<E extends Comparable<E>>
add
in class BinarySearchTree<E extends Comparable<E>>
val
- The value to be xadded.public boolean contains(E val)
contains
in interface Structure<E extends Comparable<E>>
contains
in class BinarySearchTree<E extends Comparable<E>>
val
- The comparable value to be found.
public E get(E val)
get
in class BinarySearchTree<E extends Comparable<E>>
val
- The value to be sought in tree.
public E remove(E val)
remove
in interface Structure<E extends Comparable<E>>
remove
in class BinarySearchTree<E extends Comparable<E>>
val
- The value to be removed.
public Iterator<E> iterator()
iterator
in interface Iterable<E extends Comparable<E>>
iterator
in interface Structure<E extends Comparable<E>>
iterator
in class BinarySearchTree<E extends Comparable<E>>
AbstractIterator
,
Iterator
,
Enumeration
,
Structure.elements()
public String toString()
toString
in class BinarySearchTree<E extends Comparable<E>>
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |