(Latest Revision: 04/21/2008)
Lists: Implementing a Deque
PRELIMINARIES:
You need to use material from chapters four, six and seven of Carrano for this
assignment. You also need to read the directions and examples here:
http://www.cs.csustan.edu/~john/Classes/General_Info/progAsgRules/
THE ASSIGNMENT:
- Write a driver for a deque class.
- Implement the class by "filling in blanks" in a file I give you. The
implementation:
- must be a doubly-linked ring structure,
- must employ dynamic memory allocation, and
- must be efficient.
- Do testing to show that everything works.
A deque is like a cross between a stack and a queue. A deque has a front
and a rear. You can insert an element at either the front or rear, and you
can remove an element from either the front or rear.
THE DRIVER:
Before implementing the deque class, you must write a simple driver program
that processes arbitrary lists of commands to perform operations on a deque.
The driver must fetch, interpret, and execute each command, and it must
show the results of execution.
If we take a closer look at the job of the driver, we see it must execute a
simple loop. In each pass through the loop, the program reads a one-line
command from standard input, interprets the meaning of the command, and then
executes the actions required by the command. The loop must be written so
that when the program receives the stop command it prints a
goodbye message and then exits.
It should not be a problem to develop the driver without first having a
finished deque class. However, you may need to 'tweak' the
stub code in the deque functions in
deque.cpp
to facilitate the testing of the driver code.
DRIVER INPUT AND OUTPUT:
This program reads all input from standard input, and writes all output
to standard output.
The documents
sample.in
and
sample.out
contain samples of the type of input the driver must process and the
corresponding output that the program produces.
The input consists of very simple commands that tell the driver to perform
operations on the deque. There is a stop command that tells the
program when to quit.
IMPLEMENTING THE DEQUE:
To implement the deque, you must create a deque class similar to the example
stack and queue classes we find in chapters six and seven of the Carrano
text book. You must start with copies of the
deque.h
and
deque.cpp
files in this directory and fill in the missing function bodies in
deque.cpp
as required to make the deque 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
deque.h.
Also, you must make sure the operations are adequately efficient. At best,
the work done by ~dequeClass() and Print() will be
approximately proportionate to the number of elements in the deque. There
is no way to do better than that. You must implement all the other
operations so that the amount of work done is O(1) for each operation. In
other words, for each of the other operations the amount of work done by any
call must be bounded by some constant.
COMPILING:
Assuming that your class implementation file is named deque.cpp and the file
containing your driver is named driver.cpp, you should compile the program
like this:
g++ deque.cpp driver.cpp
deque.cpp and driver.cpp should include your deque.h file.
WHAT TO TURN IN:
You will turn in two "phases" of this assignment:
- You will turn in the
driver
on
the first due date
- On
the second due date
you will turn in a
final version
of the program.
For each phase of the assignment, you will turn in a printer output (hardcopy)
and you will send me an e-mail message. Please follow these rules:
- Always send me e-mail as plain text in the main message body. Never
send me attachments.
- Always use the exact subject line I specify for each message.
(I often get hundreds of e-mail messages in a week. The subject line
allows me to find, filter and sort messages.) You will lose a
significant number of points on the assignment if you use the wrong
subject line.
- Be very careful when typing the command to send e-mail. You may use
the instructions in your
Hello World! lab excercise
for guidance. Of course, you will need to make the obvious changes to
those directions -- you have to use the correct subject line and
filename.
- Always send yourself a copy of each e-mail message you send to me, and
check to see if you receive the message intact. You are
responsible for sending e-mail correctly.
Here is a list of the things you have to turn in:
- At the start of class on the first due date,
place the following item on the "counter" in front of me:
- a hardcopy of the source code for your driver program.
Make sure that all of the content shows on the paper, is plainly
readable, and is properly formatted.
- Send the following items to me by e-mail before midnight on the first due date:
- a copy of the source code for your driver, and
- a hardcopy of your test script showing adequate testing of
the driver part of your program.
Combine the source file and the script into one
shell archive file
and e-mail me the archive file with the subject line:
CS2500Prog4.drv
- At the start of class on the second due date,
place the following item[s] on the "counter" in front of
me:
- a hardcopy of the source code for your driver program and your
deque.cpp file.
Make sure that all of the content shows on the paper, is plainly
readable, and is properly formatted.
- Send the following items to me by e-mail before midnight on the second due date:
- All source files for your final level
program (*.cpp files and *.h files)
- Your test script showing adequate testing of your final level program.
Combine the source files and the script into one
shell archive file and e-mail me the archive file with the subject
line:
CS2500Prog4.f
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 is: john@ishi.csustan.edu.
DUE DATES:
For the due dates, see
the class schedule.