Assignment 10


This assignment is an exercise in implementing the list ADT using a doubly-linked list. You will need to write a template structure to represent a list node, and a template class to represent the list.

1. Initial Setup


  1. Log in to Unix.

  2. Run the setup script for Assignment 10 by typing:

        setup 10
    

2. Files You Must Write


You will need to write one template structure and one template class for this assignment. A main program to test your class will be provided.

Since this is a C++ template, all of the code for both the structure and the class should be placed in a single file, mylist.h. That includes both structure / class definitions as well as the definitions for all of the functions. See the Hints section for an outline of how to structure this file and the order that things need to be coded.

The node structure

Data members

This template structure should have three data members: a member of the template parameter type T used to store a value to be inserted into the list, a pointer to the previous node<T> in the list, and a pointer to the next node<T> in the list.

Member functions

The mylist class

Data members

This class should have three data members. The first should be a pointer to a node<T> that will point to the front node in the list (or be nullptr if the list is empty). The second should be a pointer to a node<T> that will point to the back node in the list (or be nullptr if the list is empty). The third should be a size_t variable that will be used to store the list size, the number of elements or values currently stored in the list.

Member functions and friend functions

The mylist class should implement the following member functions and friend functions.

3. Files We Give You


The setup script will create the directory Assign10 under your csci241 directory. It will copy a makefile named makefile to the assignment directory.

You will also receive a driver program named assign10.cpp which contains a main() function that will test your mylist class.

4. Output


The correct output for this assignment is shown below:

*** Testing default constructor ***

*** Testing size(), operator<<(), and empty() with empty list ***

l1 (size 0):
l1 is empty

*** Testing push_back() into empty list ***

*** Testing size(), operator<<(), and empty() with non-empty list ***

l1 (size 1): 40
l1 is not empty

*** Testing push_back() into non-empty list ***

l1 (size 3): 40 50 60

*** Testing push_front() into empty list ***

l2 (size 1): c

*** Testing push_front() into non-empty list ***

l2 (size 3): a b c

*** Testing push_front() and push_back() ***

l1 (size 6): 10 20 30 40 50 60
l2 (size 6): a b c d e f

*** Testing read version of front() and back() ***

l1 front: 10
l1 back: 60

*** Testing write version of front() and back() ***

l1 front: 5
l1 back: 65

*** Testing pop_back() ***

l2 (size 4): a b c d

*** Testing pop_front() ***

l2 (size 2): c d

*** Testing pop to empty ***

l2 (size 0):

*** Testing copy constructor ***

l1 (size 6): 5 20 30 40 50 65
l3 (size 6): 5 20 30 40 50 65

*** Testing for shallow copy ***

l1 (size 6): 10 20 30 40 50 60
l3 (size 6): 5 20 30 40 50 65

*** Testing copy assignment operator ***

l1 (size 8): 10 20 30 40 50 60 70 80
l3 (size 8): 10 20 30 40 50 60 70 80

*** Testing for shallow copy ***

l1 (size 9): 10 20 30 40 50 60 70 80 90
l3 (size 7): 20 30 40 50 60 70 80

*** Testing self-assignment ***

l1 (size 9): 10 20 30 40 50 60 70 80 90

*** Testing chained assignment ***

l1 (size 9): 10 20 30 40 50 60 70 80 90
l3 (size 9): 10 20 30 40 50 60 70 80 90
l4 (size 9): 10 20 30 40 50 60 70 80 90

*** Testing equality operator ***

l1 and l4 are equal
l1 and l3 are not equal
l1 and l4 are not equal

*** Testing less than operator ***

l1 is less than l4
l4 is not less than l1
l1 is not less than l1
l1 is not less than l3
l3 is less than l1
l1 is not less than l3
l3 is less than l1

*** Testing clear() ***

l1 (size 0):

*** Testing for const correctness ***

l4 (size 8): 20 30 40 50 60 70 80 90
l4 is not empty
l4 front: 20
l4 back: 90
l4 and l1 are not equal
l4 is not less than l3
l4 is not less than l1
l1 is less than l4

*** Testing exception handling ***

Caught underflow exception on call to front()
Caught underflow exception on call to back()
Caught underflow exception on call to pop_front()
Caught underflow exception on call to pop_back()
Caught underflow exception on call to front()
Caught underflow exception on call to back()

If you would like a copy of this output to compare against your own program's output using the diff command, it is available on Unix at the pathname /home/turing/t90kjm1/CS241/Output/Spring2020/Assign10/output10.txt.

5. Hints