list4.h:
The header file for the new List template
class. Actually, you don't have to write much of this file.
Just start with a copy of
your header file for the List class that uses
a linked list. Change the documentation at the top to indicate
that the class is now a template class. Make sure that
you delete the part of the documentation that refers to the
typedef (because you no longer have a typedef!). You can use
the documentation at the top of page 280 as a guideline.
Also, at the bottom of the header file, change the List class definition to a template class. When you do this change, follow the pattern in Step 1 on page 277. You will also need to change link1.h (the linked list toolkit) to link2.h (the template version of the linked list toolkit), and change each of your Node* member variables to a Node<Item>* member variable.
Finally, at the bottom of the header file you will need the include statement:
#include "list4.template"
The reason for this include statement is explained in Step 3 on page 279.
list4.template:
The implementation file for the new
List template class. Notice that the name of this file ends in
".template" rather than ".cxx". This is to remind you that
template implementation files are never compiled on their own.
To implement this file, start with a copy of the implementation from your ordinary list class and make the changes described in Step 2 on page 277. Some further clarifications are given on pages 278-286 and 295-296 (using the Bag class as an example).
listtest.cxx:
This is the same interactive
test program that you used with the earlier Lists.
If you want to use it with the new list, then copy it to your
directory and open it with your editor. Then change the
statement
#include "list1.h"
#include "list4.h"
listex4.cxx:
A non-interactive test program that will
be used to grade the correctness of your new List class.
link2.h
and
link2.template:
Copy these files to your hw06 subdirectory. They contain the
template version of the linked
list toolkit from Section 6.4. You may use these files without
changing them.
Most of your work consists of following the pattern for converting a container class to a template class, as shown on pages 277-279. Also, you must use the template version of the linked list toolkit (link2.h instead of link1.h), and each Node* variable will be changed to a Node<Item>* variable. The conversion of the Bag (in Section 6.5) may serve as a good example to follow.
template <class Item> class ListIterator { public: // CONSTRUCTOR ListIterator( ); // MODIFICATION MEMBER FUNCTIONS void attach(List<Item>& attached_list); void advance( ); // CONSTANT MEMBER FUNCTIONS Item current( ) const; bool is_item( ) const; ... };Most of the member functions that are listed above are similar to the Bag's external iterator in Project 5 on page 305. However, the is_item function has an extra requirement: is_item() should return true only if the iterator has a current item and the attached List has not been changed since the attachement was made. How are you going to manage this last requirement? Here is one idea: