jds.collection
Class AVLTree

java.lang.Object
  |
  +--jds.collection.AVLTree

public class AVLTree
extends java.lang.Object
implements Bag, Sorted, FindMin, SortAlgorithm

AVLTree - set kept in a balanced binary search tree; for use with book Classic Data Structures in Java by Timothy A Budd, published by Addison-Wesley, 2001.

See Also:
Collection, Serialized Form

Constructor Summary
AVLTree()
          initialize newly created AVL tree
AVLTree(java.util.Comparator t)
          initialize newly created AVL tree
 
Method Summary
 void addElement(java.lang.Object val)
          add a new value to the collection
 boolean containsElement(java.lang.Object val)
          see if collection contains value
 java.util.Enumeration elements()
          Yields enumerator for collection
 java.lang.Object findElement(java.lang.Object val)
          find element that will test equal to value
 java.lang.Object getFirst()
          return the smallest element from the collection
 boolean isEmpty()
          Determines whether the collection is empty
 void removeElement(java.lang.Object val)
          remove a new value from the collection
 void removeFirst()
          remove the smallest element from the collection
 int size()
          Determines number of elements in collection
 void sort(Indexed data)
          rearrange collection into asending order
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AVLTree

public AVLTree(java.util.Comparator t)
initialize newly created AVL tree
Parameters:
t - comparator object used to order elements

AVLTree

public AVLTree()
initialize newly created AVL tree
Method Detail

isEmpty

public boolean isEmpty()
Determines whether the collection is empty
Returns:
true if the collection is empty

size

public int size()
Determines number of elements in collection
Returns:
number of elements in collection as integer

elements

public java.util.Enumeration elements()
Yields enumerator for collection
Returns:
an Enumeration that will yield the elements of the collection
See Also:
Enumeration

containsElement

public boolean containsElement(java.lang.Object val)
see if collection contains value
Specified by:
containsElement in interface Bag
Parameters:
val - element to be tested
Returns:
true if collection contains value

findElement

public java.lang.Object findElement(java.lang.Object val)
find element that will test equal to value
Specified by:
findElement in interface Bag
Parameters:
value - element to be tested
Returns:
first value that is equals to argument
Throws:
java.util.NoSuchElementException - no matching value

addElement

public void addElement(java.lang.Object val)
add a new value to the collection
Specified by:
addElement in interface Bag
Parameters:
value - element to be inserted into collection

removeElement

public void removeElement(java.lang.Object val)
remove a new value from the collection
Specified by:
removeElement in interface Bag
Parameters:
value - element to be removed from collection
Throws:
java.util.NoSuchElementException - no matching value

getFirst

public java.lang.Object getFirst()
return the smallest element from the collection
Specified by:
getFirst in interface FindMin

removeFirst

public void removeFirst()
remove the smallest element from the collection
Specified by:
removeFirst in interface FindMin

sort

public void sort(Indexed data)
rearrange collection into asending order
Specified by:
sort in interface SortAlgorithm
Parameters:
data - the values to be ordered

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object