Homework 7

Computer Architecture I ShanghaiTech University
HW6 HW7

Goals

In this assignment you can finally code in C++ again. Topics covered are:

Setup

Copy the following files to the gradebot: doubllt.h, doubllt.hpp, main.cpp and Makefile.

Overview

Your task is to implement a doubly linked list in C++ using templates. If in doubt its behaviour should be similar to the std::list. But of course the std::list is more complicated - we implement a simplified version. doubllt.h defines most of the classes needed and some of their data structures and methods. Other methods are left for you to declare. Follow the instructions in doubllt.h to see what you should implement. doubllt.hpp contains the implementation of the different functions. For templates the program that is using them has to always include the implementation as well, because we cannot generate and link to a .o file because the code depends on the template parameter. To keep the code clean it is one convention to still only declare the classes and functions in a .h file while its implementation goes into a .hpp file which is included at the end of the .h file. To help you get started some functions are already (partially) implemented. main.cpp contains a few test cases.

Task 1 (80%)

Declare and implement the missing functions in doubllt.h and doubllt.hpp. You are not allowed to change any of the existing function declarations. For the ones which are not well specified use std::list as a reference. You are not allowed to #include anything in the doubllt.* files or use any external library in there.

Task 2 (10%)

Answer the questions in the beginning of main.cpp by adding them to the comments.

Task 3 (10%)

In main.cpp implement a test case:

We want to store C-arrays of doubles in the doubly linked list. But we do not want to store them directly in there but only a pointer to them. We have to make sure that under no circumstances we will have a memory leak - so deleting the arrays at the end by hand is not an option. Is there maybe something in the standart template library that can help? (Answer: YES!) Tasks:

Grading

Task 1 will be auto-graded by the gradebot - the code for this will be added Sunday, May 29th. Tasks 2 and 3 will be graded by hand.
The gradebot will enforce that the number of comments is at least 25% of the non blank lines. The TA's will check by hand if those comments are valid and in English - failure to comply may lead to a score of 0 for this HW.