template <class T> class List

A Doubly-Linked List

Inheritance:

List


public members:

inline List ()
List (const List<T>& rhs)
List<T>& operator= (const List<T>& rhs)
inline ~List()
inline void prepend (const T& value)
inline void append (const T& value)
void add (const T& value)
void join (const List<T>& src)
void catenate (List<T>& src)
void clear ()
inline List<T>* copy () const
inline T& firstElement () const
inline T& lastElement () const
bool includes (const T& value) const
bool operator== (const List<T>& rhs) const
bool operator!= (const List<T>& rhs) const
inline bool isEmpty () const
inline bool isNotEmpty () const
int length () const
inline void removeFirst ()
inline void removeLast ()
inline const T& operator[] (const ListIterator<T>& li) const
inline T& operator[] (const ListIterator<T>& li)
void remove (const T& value)
void remove (const List<T>& lst)
void remove (ListIterator<T>& lit)
inline void replace (ListIterator<T>& li, const T& val)
inline void addAfter (ListIterator<T>& lit, const T& val)
inline void addBefore (ListIterator<T>& lit, const T& val)
inline ListIterator<T> first () const
inline ListIterator<T> last () const

Documentation

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.

Think of a ListIterator<T> as a pointer to an object in the List<T>. You can access the element currently pointed to by the iterator, move the iterator forward and backward through the List<T>, and use it as a mechanism to define where elements should be inserted and deleted. If the iterator is moved off the end of the list it behaves as a null pointer.

This is a concrete class, not a polymorphic one.

inline List ()
Construct an empty List<T>.

List (const List<T>& rhs)
The copy constructor.

List<T>& operator= (const List<T>& rhs)
The assignment operator.

inline ~List ()
The destructor.

inline void prepend (const T& value)
Adds a copy of the value to the beginning of the List<T>.

inline 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>. This differs from join() in that it unlinks the objects from the List<T> src and glues them to the end of this List<T>, leaving List<T> src empty. This is more efficient that join() if src is no longer needed.

void clear ()
Removes all objects from the List<T>.

inline List<T>* copy () const
Returns a copy of this List<T> on the heap. It is the user's responsibility to delete this when no longer needed.

inline T& firstElement () const
Returns a reference to the first element in the List<T>.

inline 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. Type T must have an operator==() defined, or be an intrinsic type.

bool operator== (const List<T>& rhs) const
Returns true if the this and rhs are memberwise equal; i.e. the two lists are the same size and each of the elements in the list compare equal. Type T must have an operator==() defined, or be an intrinsic type.

bool operator!= (const List<T>& rhs) const
Returns true if the this and rhs are not equal.

inline bool isEmpty () const
Returns true if the List<T> is empty.

inline bool isNotEmpty () const
Returns true if the List<T> is not empty.

int length () const
Returns the number of objects in the List<T>.

inline void removeFirst ()
Removes the first element in the List<T>.

inline void removeLast ()
Removes the last element in the List<T>.

inline const T& operator[] (const ListIterator<T>& li) const
Returns reference to object pointed to by the ListIterator<T>.

inline 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 lst.

void remove (ListIterator<T>& lit)
Removes the object pointed to by the ListIterator<T>.

inline void replace (ListIterator<T>& li, const T& val)
Replace the value pointed to by the ListIterator<T> by val.

inline void addAfter (ListIterator<T>& lit, const T& val)
Insert val into List<T> after the object pointed to by ListIterator<T>.

inline void addBefore (ListIterator<T>& lit, const T& val)
Insert val into List<T> before the object pointed to by ListIterator<T>.

inline ListIterator<T> first () const
Returns a ListIterator<T> to the first object in this List<T>.

inline ListIterator<T> last () const
Returns a ListIterator<T> to the last object in this List<T>.


this class has no child classes.

alphabetic index hierarchy of classes


Chombo

Copyright Notice

This software is copyright (C) by the Lawrence Berkeley National Laboratory. Permission is granted to reproduce this software for non-commercial purposes provided that this notice is left intact.

It is acknowledged that the U.S. Government has rights to this software under Contract DE-AC03-765F00098 between the U.S. Department of Energy and the University of California.

This software is provided as a professional and academic contribution for joint exchange. Thus it is experimental, is provided ``as is'', with no warranties of any kind whatsoever, no support, no promise of updates, or printed documentation. By using this software, you acknowledge that the Lawrence Berkeley National Laboratory and Regents of the University of California shall have no liability with respect to the infringement of other copyrights by any part of this software.