Project 2: Doubly-Linked List Container -- STL Interface

Due: Mon, Feb 19

Objectives: Understanding generic programming and information hiding by developing generic containers. Getting familiar with the concept of class template and its usage. Use of nested (iterator) classes. Use of namespace. Operator overloading. 

Task: Implement a doubly-linked list class template List and its associated iterators, with the same interface and iterator usage as that found in the C++ STL

Requirements:

  1. A header file List.h is provided, which contains the interfaces of the doubly-linked list class template List. In particular, it contains a nested Node structure, and two nested iterators class (iterator and const_iterator). You cannot change anything in the List.h file.

  2. A sample driver program test_list.cpp has been included. It is an example test program that will run some tests on your implementation of the doubly-linked list class template for different data types (it tests List<int> and List<string>. Don't make any changes to this driver program. However, your class will be tested with more than just this sample driver. It is recommended that you write other driver programs of your own, for more thorough testing.

  3. You need to implement the member functions of the doubly-linked list class template List in a file named List.hpp. Note that List.hpp has been #included in the header file List.h (towards the end of the file). As we have discussed in class, you should not try to compile List.hpp (or List.h) by themselves. These comprise a header that will be #included into other programs you might write.

    You need to implement all the member functions of List<T>, List<T>::iterator, and List<T>::const_iterator, and non-class overloaded functions operator==(), operator!=(), and operator<<() included in List.h. The design of the List container follows the one presented in the textbook. It has three member variables, theSize, head, and tail. theSize records the number of elements in the list. The head and tail pointers point to the sentinel nodes. They represent the beginning and end markers. They do not store any real elements in the list. It is OK for you to use the code provided in the textbook, but note that the definitions will be in the List.hpp file here, not defined inline in the class definition block, like they are in the textbook. Also, this implementation will contain more features than those in the textbook's implementation, so there will be some new functions for you to write. We describe the requirements of each function in the following (this specification may not write the function prototypes in detail, so please refer to the List.h file for the detailed function prototype).

            Member functions of nested const_iterator class:

            Member functions of nested iterator class:

            Member functions of List class template 

           Non-class functions 

  1. Write a makefile for your project, to compile the test_list.cpp driver into an executable called proj2.x. Your program must be able to compile and run on the linprog machines.

  2. Analyze the worst-case run-time complexities of the member functions reverse() and remove_if(). Give the complexities in the form of Big-O. Your analysis can be informal; however, it must be clearly understandable by others. Name the file containing the complexity analysis as "analysis.txt".

Downloads

Here again are links to the List.h and sample test driver, as well as my output from the test_list.cpp driver program (myout.txt).

Submission

Tar up List.hpp, your makefile, and analysis.txt into a single tar archive and submit online via Canvas, in the "Assignments" section. Use the Assignment 2 link to submit. Make sure you tar your programs correctly.

Your tar file should be named in this format, all lowercase:

        lastname_firstname_p2.tar

        Example:  My tar file would be:     myers_bob_p2.tar