Public Methods |
| List () |
| Construct an empty List<T>.
|
| List (const List< T > &rhs) |
| The copy constructor.
|
List< T > & | operator= (const List< T > &rhs) |
| The assignment operator.
|
| ~List () |
| The destructor.
|
void | prepend (const T &value) |
| Adds a copy of the value to the beginning of the List<T>.
|
void | append (const T &value) |
| Adds a copy of the value to the end of the List<T>.
|
void | add (const T &value) |
| Adds a copy of the value to the end of the List<T>.
|
void | join (const List< T > &src) |
| Appends a copy of all items in List<T> src to this List<T>.
|
void | catenate (List< T > &src) |
| Appends a copy of all items in List<T> src to this List<T>.
|
void | clear () |
| Removes all objects from the List<T>.
|
List< T > * | copy () const |
| Returns a copy of this List<T> on the heap.
|
T & | firstElement () const |
| Returns a reference to the first element in the List<T>.
|
T & | lastElement () const |
| Returns a reference to the last element in the List<T>.
|
bool | includes (const T &value) const |
| Returns true if the List<T> contains an object identical to value.
|
bool | operator== (const List< T > &rhs) const |
| Returns true if the this and rhs are memberwise equal.
|
bool | operator!= (const List< T > &rhs) const |
| Returns true if the this and rhs are not equal.
|
bool | isEmpty () const |
| Returns true if the List<T> is empty.
|
bool | isNotEmpty () const |
| Returns true if the List<T> is not empty.
|
int | length () const |
| Returns the number of objects in the List<T>.
|
void | removeFirst () |
| Removes the first element in the List<T>.
|
void | removeLast () |
| Removes the last element in the List<T>.
|
const T & | operator[] (const ListIterator< T > &li) const |
| Returns reference to object pointed to by the ListIterator<T>.
|
T & | operator[] (const ListIterator< T > &li) |
| Returns reference to object pointed to by the ListIterator<T>.
|
void | remove (const T &value) |
| Removes all objects in the List<T> equal to value.
|
void | remove (const List< T > &lst) |
| Removes all objects in the List<T> equal to any of the values in \rm lst.
|
void | remove (ListIterator< T > &lit) |
| Removes the object pointed to by the ListIterator<T>.
|
void | transfer (ListIterator< T > &lit) |
| Transfer the object pointed to by lit from the List<T> lit is associated with to this one.
|
void | replace (ListIterator< T > &li, const T &val) |
| Replace the value pointed to by the ListIterator<T> by val.
|
void | addAfter (ListIterator< T > &lit, const T &val) |
| Insert val into List<T> after the object pointed to by lit.
|
void | addBefore (ListIterator< T > &lit, const T &val) |
| Insert val into List<T> before the object pointed to by lit.
|
ListIterator< T > | listIterator () const |
| Returns a ListIterator<T> to the first object in this List<T>.
|
ListIterator< T > | first () const |
| Returns a ListIterator<T> to the first object in this List<T>.
|
ListIterator< T > | last () const |
| Returns a ListIterator<T> to the last object in this List<T>.
|
Protected Methods |
void | remove (ListLink< T > *ln) |
void | removeLink (ListLink< T > *ln) |
ListLink< T > * | addBefore (ListLink< T > *ln, const T &val) |
ListLink< T > * | addAfter (ListLink< T > *ln, const T &val) |
Protected Attributes |
ListLink< T > * | head |
ListLink< T > * | tail |
Static Protected Attributes |
Pool | linkPool |
Friends |
class | ListIterator< T > |
The List<T> class is a template class that implements a doubly-linked list of objects. A List<T> is a useful container class when the number of objects in the collection is not known ahead of time. A List<T> can contain an arbitrary number of elements; operations such as insertion, deletion, and catenation are easily implemented and inexpensive.
The only difficulty when defining a list class is devising a mechanism to access the elements. In an array, an element is accessed using an integer index. Since the elements in a List<T> are ordered by position, we could define an integer indexing operation that walks along the List<T> links from the beginning until the numbered element is found. Unfortunately, this would be very inefficient when accessing elements near the end of a long list. Another solution is to allow user access to the individual link objects that contain the element as well as the forward and backward pointers. This is not a satisfactory solution since it allows user access to the internal representation of the class. The solution chosen is to define a ListIterator<T> template class.
This is a concrete class, not a polymorphic one.