(Latest Revision: 04/21/2002)
Lists: Implementing a Circular List
Before starting this assignment it is imperative that you be
familiar with chapter 4 of Carrano, including the section
entitled "Variations of the Linked List." You also need to read
the directions and examples here:
A circular linked list is a linked list in which the last element
points back to the first element, instead of having a NULL
pointer. You can get a lot of ideas on how to write the code for
the new circular list class by looking at the "regular" linked
list implementation code:
Also you should read pages 206-208 for more help. You must be
careful to understand where and how the new "cListP" code must be
different from the "ListP" code.
- Write a driver for a list-of-strings class.
- Implement a new list class by using the files
"filling in blanks" in
- must be a singly-linked circular list
- must employ an external pointer to the last node,
- must use a NULL value in the external pointer to
indicate an empty list,
- must not employ any dummy nodes,
- must employ dynamic memory allocation, and
- must be efficient.
- Do testing to show that your cListP.h, cListP.cpp, and
driver work together properly.
Before implementing the new list class, you must write a simple
driver program that processes arbitrary lists of commands to
perform operations on a list.
The driver must:
If we take a closer look at the job of the driver, we see it must
execute a "command loop." In each pass through the loop, the
program reads a one-line command from standard input, interprets
the meaning of the command, echos the command to the standard
output, executes the actions required by the command, and tells
the results of the command. (The print command mostly just prints
and does little additional "telling.")
- create a list variable, and
- fetch, echo, interpret, execute, and tell the results of
each command in the input,
The command loop must be written so that when it receives the
stop command it prints a goodbye message and then
It should not be a problem to develop the driver before the new
list class is finished. For example, you can just put stub code
in the functions of
and then test run the driver. When the driver executes, it will
call the stub functions in cListP.cpp. Alternatively, you can
make a minor modification in a "#include" directive in the
driver, re-compile, and then test the driver using the "ListP"
implementation of the list class. When programs are written in a
modular fashion, this kind of thing is very easy to do. It's
like plugging your headphones into one CD player, and then
another -- pretty simple and easy to do.
I suggest you implement the "print" command completely within the
driver. Make it a function inside the driver that uses the
ListRetrieve function of the list class to retrieve and print
each element of the list.
DRIVER INPUT AND OUTPUT:
This program reads all input from standard input, and writes all
all output to standard output.
contain samples of the type of input the driver must process and
the corresponding output that the program produces. (They are
not intended to test the program exhaustively, so
you still need to create more input files to use when you
test out your program. )
The input consists of very simple commands that tell the driver
to perform operations on the list. There is a stop
command that tells the program when to quit.
IMPLEMENTING THE NEW LIST CLASS:
You must create a new list class similar to the "ListP"
singly-linked version of the list class we studied in chapter
four of the Carrano text book. You must start with copies of the
files in this directory and fill in the missing function bodies in
as required to make the list class operational.
You must write the function bodies so that the functions are
implemented exactly as specified by the function
prototypes and the the function header comments in
Also, you must make sure the operations are adequately efficient.
The work done by PtrTo, ~listClass, and
Print should be bounded by a constant times the number
of elements in the list. There is no way to do better than that,
and the code should not do worse than that.
ListRetrieve, ListInsert, and
ListDelete will need to call PtrTo. Besides
the work done by PtrTo, the rest of the work these
functions do should be bounded by a constant.
The amount of work done by listClass,
ListIsEmpty, and ListLength must be bounded by
Assuming that your class implementation file is named cListP.cpp
and the file containing your driver is named driver.cpp, you
should compile the program like this:
g++ cListP.cpp driver.cpp
include cListP.h in cListP.cpp and driver.cpp. (Do not
include cListP.cpp in driver.cpp or vice-versa.)
WHAT TO TURN IN:
You will turn in two sets of hardcopies and you will send two
With regard to the e-mail please follow these rules:
Here is a list of the things you have to turn in:
- Always send me e-mail as plain text in the main message
body. Never send me attachments.
- I will tell you what subject line to use with each message,
and I need you to use exactly the subject lines I
give you. (I get hundreds of e-mail messages at a time and
your subject line allows me to sort messages.)
Note that there are no spaces in the subject lines given. It is
important that you do not insert any spaces. My e-mail address
- On the morning of the first due date , turn
in a hardcopy of your completed driver code.
- Send me an e-mail copy of your completed driver code before
midnight on the first due date. Send it by
e-mail with the subject line: CS2500,prog4.drv.
- On the morning of the second due date , turn
in a hardcopy of your completed driver code, cListP.h file,
and cListP.cpp file.
- Send the following items to me by e-mail before midnight on
the second due date:
Include all header and source files (all *.h
files and *.cpp files) that are required to compile the
program into an executable image -- everything I need to
compile the program. Combine all the source files
and the script into one
shell archive file
and e-mail me the archive file with the subject line:
- A final version of the source code, and
- a script showing your test runs.
For the due dates, see
the class schedule.