Defining Class TList < T >
template <typename T>
class TList
{
friend class TListIterator<T>;
public:
// first some scope TList<T>:: type definitions to facilitate clients
typedef T value_type;
typedef TListIterator<T> Iterator;
// constructors
// copy constructor is pivate
TList (); // default constructor
~TList (); // destructor
TList (const TList<T>& L); // copy constructor
TList<T>& operator = (const TList<T>& L); // assignment
// modifying List structure
bool PushFront (const T& t); // Insert t at front of list
bool PushBack (const T& t); // Insert t at back of list
bool Insert (Iterator& I, const T& t); // Insert t at I
bool PopFront (); // Remove the Tval at front
bool PopBack (); // Remove the Tval at back
bool Remove (Iterator& I); // Remove item at I
unsigned int Remove (const T& t); // Remove all copies of t
void Clear (); // Empty the list, deleting all elements
// information about the list
unsigned int Size () const; // return the number of elements on the list
bool Empty () const; // true iff list has no elements
// accessing values on the list
T& Front (); // return reference to element at front of list
const T& Front () const; // const version
T& Back (); // return reference to element at back of list
const T& Back () const; // const version
// locating places on the list
Iterator Begin () const;
Iterator End () const;
Iterator rBegin () const;
Iterator rEnd () const;
// a generic display method
void Display (ostream& os, char ofc = '\0') const;
protected:
// A scope TList<T>:: class usable only by its friends (all members are private)
class TLink
{
friend class TList<T>;
friend class TListIterator<T>;
// TLink data
T value; // data
TLink * prevLink; // ptr to predecessor Link
TLink * nextLink; // ptr to successor Link
// TLink constructor - parameter required
TLink(const T& Tval);
} ;
// structural data
TLink * firstLink, // pointer to the first element in the list
* lastLink; // pointer to the last element in the list
// protected method -- used only by other methods
void Clone (const TList<T>& L); // makes *this a clone of L
} ;
// global scope operators and functions
template <typename T>
bool operator == (const TList<T>& L1, const TList<T>& L2);
template <typename T>
bool operator != (const TList<T>& L1, const TList<T>& L2);
template <typename T>
ostream& operator << (ostream& os, const TList<T>& L);