Homework 7 (Extra Credit) - Iterators of Template Classes

Due: Thursday March 17, 2011 at noon.
NOTE: Since this is an extra credit assignment, no late submissions will be accepted.

Coding Conventions

Use the same coding conventions as described in Homework 1. Additionally, make sure to indent each section of the class in the class definition.

Assignment

The purpose of this assignment is to create an iterator for the GenericList template class that you created in Homework 6. This will be similar to the C++ iterator for the vector class from the standard template library (STL) described in Section 16.5 of the book.

An iterator is used to access individual elements within a container class (a class that contains a set of values). They are essentially wrappers around pointers to elements in the container class. Since GenericList is a template class, the iterator for GenericList will also be a template class. Iterators can be initialized to a specific address (element in the container class) and can then be incremented or decremented to move along the elements in the container class (iterate over the elements, hence the name iterator).

The iterator class will have the following features:

The GenericList class will also need to be modified by adding two new public member functions to support iterators. These are: Test your iterator with a main() function that implements the following pseudocode. This is similar to what the book does with vector iterators in Program 16-14.
create a GenericList<int> object called list
create an Iterator<int> object called iter
for i = 0 to i < 10
  call list.push_back(i) 
end-for
for iter = list.begin() to iter < list.end()
  cout the dereferenced iter
end-for
decrement the iter object
cout the iter object (this should print the address of the last element)
Email the completed assignment to me.