Data Structures - Chapter 5 - Programming Assignment
The Linked List Version of the Sequence Class

Data Structures and Other Objects Using C++
by Michael Main and Walter Savitch
ISBN 0-8053-7470-1, Softcover, 784 pages, 1997


The Assignment:
You will implement and test a revised sequence class that uses a linked list to store the items.
Purposes:
Ensure that you can write a small class that uses linked lists.
Before Starting:
Read all of Chapter 5, with particular attention to Sections 5.3 and 5.4.
Due Date:
Midnight Sunday June 20 2004
Submitting your code:
Leave all files in directory lab4 in your 2440 directory. Leave a readme file if you have special instructions for running your program.
gdb - The GNU Debugger
As you know, when working with C++ programs, you'll often find yourself with such runtime errors as Segmentation fault, or Floating point exception. Those error messages are not overly helpful to you to identify what is wrong with your program. Fortunately, there is a tool to help is find where these problems are occurring - a debugger. Go through this gdb Overview to see how to use gdb.

Files that you must write:
  1. node1.h and node1.C are provided for you and are located in the lab4 directory.
  2. sequence3.h: The header file for the new sequence class. Actually, you don't have to write much of this file. Just start with our version and add your name and other information at the top. If some of your member functions are implemented as inline functions, then you may put those implementations in this file too. By the way, you might want to compare this header file with your first sequence header file (sequence1.h), and second sequence header file (sequence2.h). The linked list version no longer has a CAPACITY constant nor a DEFAULT_CAPACITY constant because the items are stored on a linked list instead of an array.
  3. sequence3.C: The implementation file for the new sequence class. You will write all of this file, which will have the implementations of all the sequence's member functions.
Other files that you may find helpful:
  1. sequence_test.C: This is the same interactive test program that you used with the earlier sequences. If you want to use it with the new sequence, then copy it to your directory and open it with your editor. Change the statement
    #include "sequence1.h"
    to
    #include "sequence3.h"
  2. sequence_ex3.C: A non-interactive test program that will be used to grade the correctness of your new sequence class.
  3. To make life easier and to also make compiling the test file easier, copy the following into a file named makefile and then change the string <TAB> to a real tab made by hitting the tab key. You will have to do this in two different places. Then when you want to compile, just say "make s_exam" or "make s_test". An example makefile is available in the lab4 directory. Here is what needs to go in your makefile:
    s_exam: sequence3.h sequence3.C node1.h  node1.C sequence_ex3.C
    <TAB>g++ -Wall sequence3.C sequence_ex3.C node1.C -o s_exam
    
    s_test: sequence3.h sequence3.C node1.h node1.C sequence_test.C
    <TAB>g++ -Wall sequence3.C sequence_test.C node1.C -o s_test
    
    Note: If you are using vim with the .vimrc supplied by Andy Dalton using <TAB> will get you 4 spaces, not a tab character. The makefile requires the tab character. To disable the conversion of the tab character to 4 spaces, type:
        :set noexpandtab
    
    before you start working on the makefile. Also note this change will only take effect in the current vim session. If you quit, and wish to make further modifications, you'll have to reset that variable.

    See My Make Tutorial for more detailed information on make and makefiles.


The sequence Class Using a Linked List
Discussion of the Assignment

Your sequence class for this assignment will differ from the your previous sequence in the following ways:

Start by declaring the new sequence's private member variables in sequence3.h. You might try declaring these variables yourself, and then compare your solution with the suggestion in Section 5.4.

Once again, do your work in small pieces. For example, my first version of the sequence had only a constructor, start, insert, advance, and current. My other member functions started out as stubs.

Use the interactive test program to track down errors in your implementation. If you have an error, do not start making changes until you have identified the cause of the error.


Michael Main (main@colorado.edu)