Class SortedSet<E extends Comparable<? super E>>

java.lang.Object
  extended by AbstractSet<E>
      extended by SortedSet<E>
All Implemented Interfaces:
ISet<E>, Iterable<E>

public class SortedSet<E extends Comparable<? super E>>
extends AbstractSet<E>

In this implementation of the ISet interface the elements in the Set are maintained in ascending order. The data type for E must be a type that implements Comparable. Students are to implement methods that were not implemented in AbstractSet and override methods that can be done more efficiently. An ArrayList must be used as the internal storage container. For methods involving two set, if that method can be done more efficiently if the other set is also a SortedSet do so.


Constructor Summary
SortedSet()
          create an empty SortedSet
SortedSet(ISet<E> other)
          create a SortedSet out of an unsorted set.
 
Method Summary
 E first()
          Return the smallest element in this SortedSet.
 E last()
          Return the largest element in this SortedSet.
 
Methods inherited from class AbstractSet
toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface ISet
add, addAll, clear, contains, containsAll, difference, equals, intersection, iterator, remove, size, union
 

Constructor Detail

SortedSet

public SortedSet()
create an empty SortedSet


SortedSet

public SortedSet(ISet<E> other)
create a SortedSet out of an unsorted set.

Parameters:
other - != null, all elements in other implement Comparable and they are mutually comparable
Method Detail

first

public E first()
Return the smallest element in this SortedSet.
pre: size() != 0

Returns:
the smallest element in this SortedSet.

last

public E last()
Return the largest element in this SortedSet.
pre: size() != 0

Returns:
the largest element in this SortedSet.