Project 10 Extra Notes

Deques and Doubly Linked Lists

The double-ended queue, or deque, is a very natural fit for a doubly-linked list, since you get fast inserts and removes, and don't have to rellocate an array.

The array implementation has advantages too, but is used mainly when you want random access to all elements. It's also significantly more complicated to write. STL Deque will be discussed in lecture.

Implementation

This deque is a template. Template syntax is a pain at first and easy to mess up. You would be insane not to start with stubs for this one.

Most of the functions do not require iteration, but you need to be careful that you relink everything properly. Head should point to the "front" of the chain, and Tail to the "back" (this should be obvious, but people seem to mess it up a lot).

If you use dummy nodes, then iteration stops when your pointer is the same as Head or Tail, except in display, since you need to display the dummy nodes.

display()

Use a table. It should be aligned in columns with proper headers.

Follow the suggestions in the project notes file. The main thing I would add is that you should put the node address (this) between Pred and Succ. This will make it easy to see that the chain is linked correctly, since you'll get each address 3 times diagonally.


Last edited 4/7