template<class TYPE> class GList: public GContainer<TYPE>

Doubly linked list.

Inheritance:


Public Fields

[more] Inserts an element after the last element of the list.

Public Methods

[more] GList()
Null Constructor.
[more] GList(const GContainer<TYPE> &gc)
Constructs a list by copying the elements of container gc.
[more] GList(const GList<TYPE> &gc)
Constructs a list by copying the elements of list gc.
[more] ~GList()
Virtual destructor.
[more]int isempty() const
Tests whether a list is empty.
[more]TYPE& operator[](GPosition pos)
Returns a reference to the list element at position pos.
[more]const TYPE& operator[](GPosition pos) const
Returns a constant reference to the list element at position pos.
[more]int operator==(const GList<TYPE> &l2) const
Compares two lists.
[more]int nth(unsigned int n, GPosition &pos) const
Initializes position pos for accessing the n-th list element.
[more]int contains(const TYPE &elt) const
Tests whether the list contains a given element.
[more]int search(const TYPE &elt, GPosition &pos) const
Searches the list for a given element.
[more]void empty()
Erases the list contents.


Inherited from GContainer:

Public Methods

ovirtual const TYPE* get(const GPosition &pos) const
ovirtual TYPE* get(const GPosition &pos)


Inherited from GContainerBase:

Public Methods

ovirtual int size() const
ovirtual GPosition firstpos() const
ovirtual GPosition lastpos() const
ovirtual void nextpos(GPosition &pos) const
ovirtual void prevpos(GPosition &pos) const


Documentation

Doubly linked list. Template class GList<TYPE> implements a doubly linked list of elements of type TYPE. Member functions are provided to search the list for an element, to insert or delete elements at specified positions.

This template class must be able to access

o GList()
Null Constructor. Constructs a list with zero elements.

o GList(const GContainer<TYPE> &gc)
Constructs a list by copying the elements of container gc.
Parameters:
gc - container from which elements will be copied.

o GList(const GList<TYPE> &gc)
Constructs a list by copying the elements of list gc.
Parameters:
gc - list from which elements will be copied.

o ~GList()
Virtual destructor.

oint isempty() const
Tests whether a list is empty. Returns a non zero value if the list contains no elements.

oTYPE& operator[](GPosition pos)
Returns a reference to the list element at position pos. This reference can be used for both reading (as "a[n]") and modifying (as "a[n]=v") a list element. An exception GException is thrown if pos is not a valid position for this list. See GPosition for efficient operations on positions.

oconst TYPE& operator[](GPosition pos) const
Returns a constant reference to the list element at position pos. This reference only be used for reading a list element. An exception GException is thrown if pos is not a valid position. This variant of operator[] is necessary when dealing with a constGList<TYPE>. See \Ref{GPosition} for efficient operations onpositions.

oint operator==(const GList<TYPE> &l2) const
Compares two lists. Returns a non zero value if and only if both lists contain the same elements (as tested by TYPE::operator==(const TYPE&) in the same order.

oint nth(unsigned int n, GPosition &pos) const
Initializes position pos for accessing the n-th list element. If the list contains less than n elements, function nth returns zero and the position pos is left unchanged. Otherwise function nth returns a non zero value. Position pos can be subsequently used to access the list element with operator[](const GPosition&). The operation works by sequentially scanning the list until reaching the n-th element.

oint contains(const TYPE &elt) const
Tests whether the list contains a given element. Returns a non zero value if and only if the list contains an element equal to checked by TYPE::operator==(const TYPE&).

oint search(const TYPE &elt, GPosition &pos) const
Searches the list for a given element. If position pos is a valid position for this list, the search starts at the specified position. If position pos is not a valid position, the search starts at the beginning of the list. The list elements are sequentially compared with

is equal to position of this list element and returns a non zero value. If however the search reaches the end of the list, function search returns zero without altering pos.

ovoid empty()
Erases the list contents. All list elements are destroyed and unlinked. The list is left with zero elements.

o Inserts an element after the last element of the list.
Inserts an element after the last element of the list. The new element is initialized with a copy of argument void append(const TYPE& elt);


This class has no child classes.

Alphabetic index HTML hierarchy of classes or Java