(Latest Revision: 04/15/2001)
Lists: Implementing a Deque
PRELIMINARIES:
You need to use material from chapters 5-7 of Carrano for this assignment.
You also need to read the directions and examples here:
http://shalim.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 executes 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 fill in deque funcions in
deque.cpp
with stub code to facilitate the testing of the driver code.
DRIVER INPUT AND OUTPUT:
This program reads all input from standard input, and writes all 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 be sending me two e-mail messages. Please follow these rules:
- 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.)
Here is a list of the things you have to turn in:
- Send me a copy of your completed driver.cpp file before midnight on the
first due date. Send it by e-mail with the subject line:
CS2500,prog4.drv.
- Send the following items to me by e-mail before midnight on the
second due date:
- A final version of the source code, and
- a script showing your test runs.
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:
CS2500,prog4.fin.
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.