jds.collection
Class SortedVector

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

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

SortedVector - an indexed collection that keeps values ordered; for use with book Classic Data Structures in Java by Timothy A Budd, published by Addison-Wesley, 2001.

See Also:
Sorted, Bag, FindMin, FindNth, SortAlgorithm, Serialized Form

Constructor Summary
SortedVector(java.util.Comparator c)
          initialize new sorted vector
SortedVector(Indexed v, java.util.Comparator c)
          initialize new sorted vector
 
Method Summary
 void addElement(java.lang.Object value)
          add a new value to the collection
 boolean containsElement(java.lang.Object value)
          see if collection contains value
 java.util.Enumeration elements()
          Yields enumerator for collection
 java.lang.Object findElement(java.lang.Object obj)
          find element that will test equal to value
 java.lang.Object findNth(int n)
          find nth smallest value in collection
 java.lang.Object getFirst()
          yields the smallest element in collection
 boolean isEmpty()
          Determines whether the collection is empty
 void removeElement(java.lang.Object obj)
          remove a new value from the collection
 void removeFirst()
          removes the smallest element in collection
 int size()
          Determines number of elements in collection
 void sort(Indexed vec)
          rearrange collection into asending order
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SortedVector

public SortedVector(Indexed v,
                    java.util.Comparator c)
initialize new sorted vector
Parameters:
c - comparator object used to place values in order

SortedVector

public SortedVector(java.util.Comparator c)
initialize new sorted vector
Parameters:
c - comparator object used to place values in order
Method Detail

elements

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

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

addElement

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

getFirst

public java.lang.Object getFirst()
yields the smallest element in collection
Specified by:
getFirst in interface FindMin
Returns:
the first (smallest) value in collection

removeFirst

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

findNth

public java.lang.Object findNth(int n)
find nth smallest value in collection
Specified by:
findNth in interface FindNth
Parameters:
index - of value, from 0 to (size-1)
Returns:
value of element
Throws:
java.util.NoSuchElementException - index is illegal

containsElement

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

findElement

public java.lang.Object findElement(java.lang.Object obj)
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

removeElement

public void removeElement(java.lang.Object obj)
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

sort

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