#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 ) |
T | remove (unsigned) throw ( out_of_range ) |
T | removeFirst () throw ( NoSuchObject ) |
T | removeFirstOccurrence (const T &) throw ( NoSuchObject ) |
T | removeLast () throw ( NoSuchObject ) |
T | removeLastOccurrence (const T &) throw ( NoSuchObject ) |
T | 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 ) |
T | remove (Node< T > *) |
Private Attributes | |
Node< T > * | frontPtr |
Node< T > * | backPtr |
unsigned | sz |
Friends | |
ostream & | operator<< (ostream &, const List< T > &) |
Implementation of a List ADT using a doubly-linked list.
Copy constructor.
bad_alloc | if memory cannot be allocated. |
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.
index | the position at which to insert the object |
object | the object to be inserted |
bad_alloc | if memory cannot be allocated |
out_of_range | if the index is out of range |
|
private |
Adds the specified object to this list at the specified position.
current | the position at which to insert the object |
object | the object to be inserted |
bad_alloc | if memory cannot be allocated |
Adds all of objects in the specified list to the end of this list.
list | containing the objects to be added |
bad_alloc | if memory cannot be allocated |
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.
index | the position at which to insert the object |
list | containing the objects to be added |
bad_alloc | if memory cannot be allocated |
out_of_range | if the index is out of range |
void List< T >::addFirst | ( | const T & | object | ) | |
throw | ( | bad_alloc | |||
) |
Adds the specified object to the front of the list.
object | the object to be added to the front of the list |
bad_alloc | if memory cannot be allocated |
void List< T >::addLast | ( | const T & | object | ) | |
throw | ( | bad_alloc | |||
) |
Adds the specified object to the end of the list.
object | the object to be added to the back of the list |
bad_alloc | if memory cannot be allocated |
void List< T >::clear | ( | ) |
Clears this list by removing all of its elements.
bool List< T >::contains | ( | const T & | object | ) | const |
Returns true if this list contains the specified object
object | the specified object |
bool List< T >::empty | ( | ) | const |
Returns true if this list is empty; returns false otherwise.
T & List< T >::get | ( | unsigned | index | ) | const |
throw | ( | out_of_range | |||
) |
Returns a reference to the object at the specified position in this list.
index | the position of the object |
out_of_range | if the index is out of range |
T & List< T >::getFirst | ( | ) | const | |
throw | ( | NoSuchObject | ||
) |
Returns a reference to the first object in this list.
NoSuchObject | if no such object exists in this list |
|
private |
Returns a pointer to the node at the specified position.
index | the position of the object |
out_of_range | if the position is out of range |
T & List< T >::getLast | ( | ) | const | |
throw | ( | NoSuchObject | ||
) |
Returns a reference to the last object in this list.
NoSuchObject | if no such object exists in this list |
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.
object | the object to be found in the list |
|
private |
Sets the private data members of this list to their defaults values; that is, sets the points to null and size to zero.
ListIterator< T > List< T >::listIterator | ( | ) |
Returns a bidirectional iterator for this list.
ListIterator< T > List< T >::listIterator | ( | unsigned | index | ) | |
throw | ( | out_of_range | |||
) |
Returns a bidirectional iterator for this list that starts at the specified position.
index | the starting position of the iterator |
out_of_range | if the index is out of range |
const List< T > & List< T >::operator= | ( | const List< T > & | list | ) | |
throw | ( | bad_alloc | |||
) |
Returns a deep copy of the specified list.
list | the list to be copied. |
bad_alloc | if memory cannot be allocated. |
void List< T >::printInternal | ( | ostream & | out = cout | ) |
A utility method that prints the internal state of this list.
T List< T >::remove | ( | unsigned | index | ) | |
throw | ( | out_of_range | |||
) |
Removes and returns the object at the specified position.
index | the position of the object |
out_of_range | if the index is out of range |
Removes and returns the object to which current points.
current | the position of the object |
T List< T >::removeFirst | ( | ) | ||
throw | ( | NoSuchObject | ||
) |
Removes and returns the first object in this list.
NoSuchObject | if no such object exists in this list |
T List< T >::removeFirstOccurrence | ( | const T & | object | ) | |
throw | ( | NoSuchObject | |||
) |
Removes and returns the first occurrence of the object in this list.
object | the object in the list |
NoSuchObject | if no such object exists in this list |
T List< T >::removeLast | ( | ) | ||
throw | ( | NoSuchObject | ||
) |
Removes and returns the last object in this list.
NoSuchObject | if no such object exists in this list |
T List< T >::removeLastOccurrence | ( | const T & | object | ) | |
throw | ( | NoSuchObject | |||
) |
Removes and returns the last occurrence of the object in this list.
object | the object in the list |
NoSuchObject | if no such object exists in this list |
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.
index | the position of the object |
object | the object |
out_of_range | if the index is out of range |
unsigned List< T >::size | ( | ) | const |
Returns the size (i.e., number of objects) of this list.
T * List< T >::toArray | ( | ) | const | |
throw | ( | bad_alloc | ||
) |
Returns an array containing the objects of this list.
bad_alloc | if memory cannot be allocated. |
|
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.
out | the output stream |
list | the specified list |