Public Member Functions | Private Member Functions | Private Attributes | Friends | List of all members
List< typename > Class Template Reference

#include <list.h>

Public Member Functions

 List ()
 
 List (const List< T > &) throw ( bad_alloc )
 
 ~List ()
 
void add (unsigned, const T &) throw ( bad_alloc, out_of_range )
 
void addAll (const List< T > &) throw ( bad_alloc )
 
void addAll (unsigned, const List< T > &) throw ( bad_alloc, out_of_range )
 
void addFirst (const T &) throw ( bad_alloc )
 
void addLast (const T &) throw ( bad_alloc )
 
void clear ()
 
bool contains (const T &) const
 
bool empty () const
 
int indexOf (const T &) const
 
T & get (unsigned) const throw ( out_of_range )
 
T & getFirst () const throw ( NoSuchObject )
 
T & getLast () const throw ( NoSuchObject )
 
ListIterator< T > listIterator ()
 
ListIterator< T > listIterator (unsigned) throw ( out_of_range )
 
remove (unsigned) throw ( out_of_range )
 
removeFirst () throw ( NoSuchObject )
 
removeFirstOccurrence (const T &) throw ( NoSuchObject )
 
removeLast () throw ( NoSuchObject )
 
removeLastOccurrence (const T &) throw ( NoSuchObject )
 
set (unsigned, const T &) throw ( out_of_range )
 
unsigned size () const
 
T * toArray () const throw ( bad_alloc )
 
const List< T > & operator= (const List< T > &) throw ( bad_alloc )
 
void printInternal (ostream &=cout)
 

Private Member Functions

void add (Node< T > *, const T &) throw ( bad_alloc )
 
void initialize ()
 
Node< T > * getIthNode (unsigned) const throw ( out_of_range )
 
remove (Node< T > *)
 

Private Attributes

Node< T > * frontPtr
 
Node< T > * backPtr
 
unsigned sz
 

Friends

ostream & operator<< (ostream &, const List< T > &)
 

Detailed Description

template<typename>
class List< typename >

Implementation of a List ADT using a doubly-linked list.

Author
Mark Maloof
Version
1.1, 3/23/10

Constructor & Destructor Documentation

template<typename T >
List< T >::List ( )

Default constructor.

template<typename T >
List< T >::List ( const List< T > &  list)
throw (bad_alloc
)

Copy constructor.

Exceptions
bad_allocif memory cannot be allocated.
template<typename T >
List< T >::~List ( )

Class destructor.

Member Function Documentation

template<typename T >
void List< T >::add ( unsigned  index,
const T &  object 
)
throw ( bad_alloc,
out_of_range
)

Adds the specified object to this list at the specified position.

Parameters
indexthe position at which to insert the object
objectthe object to be inserted
Exceptions
bad_allocif memory cannot be allocated
out_of_rangeif the index is out of range
template<typename T >
void List< T >::add ( Node< T > *  current,
const T &  object 
)
throw (bad_alloc
)
private

Adds the specified object to this list at the specified position.

Parameters
currentthe position at which to insert the object
objectthe object to be inserted
Exceptions
bad_allocif memory cannot be allocated
template<typename T >
void List< T >::addAll ( const List< T > &  list)
throw (bad_alloc
)

Adds all of objects in the specified list to the end of this list.

Parameters
listcontaining the objects to be added
Exceptions
bad_allocif memory cannot be allocated
template<typename T >
void List< T >::addAll ( unsigned  index,
const List< T > &  list 
)
throw ( bad_alloc,
out_of_range
)

Adds all of objects in the specified list to the specified position of this list.

Parameters
indexthe position at which to insert the object
listcontaining the objects to be added
Exceptions
bad_allocif memory cannot be allocated
out_of_rangeif the index is out of range
template<typename T >
void List< T >::addFirst ( const T &  object)
throw (bad_alloc
)

Adds the specified object to the front of the list.

Parameters
objectthe object to be added to the front of the list
Exceptions
bad_allocif memory cannot be allocated
template<typename T >
void List< T >::addLast ( const T &  object)
throw (bad_alloc
)

Adds the specified object to the end of the list.

Parameters
objectthe object to be added to the back of the list
Exceptions
bad_allocif memory cannot be allocated
template<typename T >
void List< T >::clear ( )

Clears this list by removing all of its elements.

template<typename T >
bool List< T >::contains ( const T &  object) const

Returns true if this list contains the specified object

Parameters
objectthe specified object
Returns
true if the list contains the object; false otherwise
template<typename T >
bool List< T >::empty ( ) const

Returns true if this list is empty; returns false otherwise.

Returns
true if empty; false otherwise
template<typename T >
T & List< T >::get ( unsigned  index) const
throw (out_of_range
)

Returns a reference to the object at the specified position in this list.

Parameters
indexthe position of the object
Returns
a reference to the object at the specified position
Exceptions
out_of_rangeif the index is out of range
template<typename T >
T & List< T >::getFirst ( ) const
throw (NoSuchObject
)

Returns a reference to the first object in this list.

Returns
a reference to the first object
Exceptions
NoSuchObjectif no such object exists in this list
template<typename T >
Node< T > * List< T >::getIthNode ( unsigned  index) const
throw (out_of_range
)
private

Returns a pointer to the node at the specified position.

Parameters
indexthe position of the object
Returns
a pointer to the node at the specified position
Exceptions
out_of_rangeif the position is out of range
template<typename T >
T & List< T >::getLast ( ) const
throw (NoSuchObject
)

Returns a reference to the last object in this list.

Returns
a reference to the last object
Exceptions
NoSuchObjectif no such object exists in this list
template<typename T >
int List< T >::indexOf ( const T &  object) const

Returns the position of the specified object in this list. Returns -1 if the object is not in this list.

Parameters
objectthe object to be found in the list
Returns
the position of object in the list
template<typename T >
void List< T >::initialize ( )
private

Sets the private data members of this list to their defaults values; that is, sets the points to null and size to zero.

template<typename T >
ListIterator< T > List< T >::listIterator ( )

Returns a bidirectional iterator for this list.

Returns
template<typename T >
ListIterator< T > List< T >::listIterator ( unsigned  index)
throw (out_of_range
)

Returns a bidirectional iterator for this list that starts at the specified position.

Parameters
indexthe starting position of the iterator
Returns
a bidirectional list iterator
Exceptions
out_of_rangeif the index is out of range
template<typename T >
const List< T > & List< T >::operator= ( const List< T > &  list)
throw (bad_alloc
)

Returns a deep copy of the specified list.

Parameters
listthe list to be copied.
Returns
a copy of the list.
Exceptions
bad_allocif memory cannot be allocated.
template<typename T >
void List< T >::printInternal ( ostream &  out = cout)

A utility method that prints the internal state of this list.

template<typename T >
T List< T >::remove ( unsigned  index)
throw (out_of_range
)

Removes and returns the object at the specified position.

Parameters
indexthe position of the object
Returns
the object at the specified position
Exceptions
out_of_rangeif the index is out of range
template<typename T >
T List< T >::remove ( Node< T > *  current)
private

Removes and returns the object to which current points.

Parameters
currentthe position of the object
Returns
the object at the specified position
template<typename T >
T List< T >::removeFirst ( )
throw (NoSuchObject
)

Removes and returns the first object in this list.

Returns
the object at the front of the list
Exceptions
NoSuchObjectif no such object exists in this list
template<typename T >
T List< T >::removeFirstOccurrence ( const T &  object)
throw (NoSuchObject
)

Removes and returns the first occurrence of the object in this list.

Parameters
objectthe object in the list
Returns
the first occurence of object in this list
Exceptions
NoSuchObjectif no such object exists in this list
template<typename T >
T List< T >::removeLast ( )
throw (NoSuchObject
)

Removes and returns the last object in this list.

Returns
the last object in this list
Exceptions
NoSuchObjectif no such object exists in this list
template<typename T >
T List< T >::removeLastOccurrence ( const T &  object)
throw (NoSuchObject
)

Removes and returns the last occurrence of the object in this list.

Parameters
objectthe object in the list
Returns
the last occurence of object in this list
Exceptions
NoSuchObjectif no such object exists in this list
template<typename T >
T List< T >::set ( unsigned  index,
const T &  object 
)
throw (out_of_range
)

Sets the object at the specified position to the specified object and returns the replaced object.

Parameters
indexthe position of the object
objectthe object
Returns
the replaced object
Exceptions
out_of_rangeif the index is out of range
template<typename T >
unsigned List< T >::size ( ) const

Returns the size (i.e., number of objects) of this list.

Returns
an unsigned integer indicating this list's size
template<typename T >
T * List< T >::toArray ( ) const
throw (bad_alloc
)

Returns an array containing the objects of this list.

Returns
an array containing the objects of this list
Exceptions
bad_allocif memory cannot be allocated.

Friends And Related Function Documentation

template<typename >
ostream& operator<< ( ostream &  out,
const List< T > &  list 
)
friend

Overloaded stream insertion operator that outputs the specified list to the output stream in the format [e1,e2,e3,...], where e1, e2, ... are the elements of the list.

Parameters
outthe output stream
listthe specified list
Returns
the modified output stream

The documentation for this class was generated from the following files: