Mastery exams are solo projects, this mastery is required.
You must implement the following operations for
your deque class (as member functions).
In addition, you must implement a destructor, assignment operator, and
copy constructor. You must also supply forward and reverse iterators
accessible via MakeIterator and MakeReverseIterator
member functions (these should return pointers to Iterators.)
Finally, you must overload += and + to merge two deques. Merging
two deques is NOT commutative, the operation a += b for deques
causes all of b's elements to be appended to a. The deque b is unchanged.
This should be an O(m) operation where b has m elements.
Perhaps the easiest way to meet the requirements for O(1) append and
prepend and expected O(1) access is to use an array of blocks
Each block contains a pointer to an array (or struct containing an
array) of (say 20) elements. Initially the middle cell of the block
array is the only non-NULL pointer. To prepend you can add within a
block, or add a new block before the leftmost block. A new block is
added at the right when appending/inserting causes the rightmost block
to fill. full. You'll only need to grow the block array when all its
blocks are allocated. You might try using blocks of size 1 initially,
it makes the coding easier. You might also try making each block a
class with some intelligence.
You may find it easier to implement a non-templated version of
this class first (e.g., for ints or strings) and then change the
implementation to be templated.
An example (not correct, not fully functional, but perhaps useful)
of a templated implementation using a vector
is accessible . Note that all member
functions are implemented inline, inside the class declaration.
This makes the example easier, but you should not do
this.
Templated Deques
You are to implement a templated class for double-ended queues, also
called deques. There is a deque class in the C++ standard
template library, the class described here is modeled loosely on that
class.
Implementation Details
You cannot use any classes in your implementation, the deque must be
implemented using only built-in types (e.g., no vector class, no list
class). In other words, you'll use raw C-style arrays.
You should feel free to borrow/steal code from the vector and
list classes (on acpub see ~ola/courses/lib on cs machines
see /usr/project/courses/cps008/lib.)
You must implement these
classes on your own.
Inherited Interface
Your class must be implemented by inheriting from the abstract base
class ADeque declared below and accessible from
~ola/cps108/deque/adeque.h
Submission
Submit as shown below. You must submit .h and .cc files for your
dequeue class. You must inherit from ADeque to facilitate
our test programs. You should also submit your own test program
testdeq.cc along with an explanation (in your README) of what
your test program does and how well you think it tests the correctness
of your implementation. Your makefile should be able to make the test
program. (submit either a compressed tar file or all files as shown below)
submit108 deque README Makefile *.cc *.h
Grading
This assignment is worth 25 points awarded as follows.
| Behavior | Points |
|---|---|
| Works Correctly (performance irrelevant) | 5 |
| Meets Performance Specs | 5 |
| Style/Coding standards | 5 |
| Test Programs | 5 |
| README, Writeup | 5 |
For extra credit, your deqeue class should handle it's own memory allocation, e.g., nodes that are deleted should be kept on a per-class (e.g., static) freelist and these nodes should be used when allocating new nodes. This can earn an aditional 10 points.