(Latest Revision: 10/30/2003)

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:

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 fill in deque functions 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 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:
  1. You will turn in the driver on the first due date
  2. 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: Here is a list of the things you have to turn in: 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.