p5 - Stacks, Queues, and Lists. EECS 280 - Fall 2006 Out...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Stacks, Queues, and Lists. EECS 280 -- Fall 2006 Out Tuesday, March 31st Due: Tuesday, April 21st, 11:59 PM I. Introduction This project will give you experience implementing a templated container class---the double-ended, doubly-linked list---and using the at-most-once invariant and Existence, Ownership, and Conservation rules to implement two simple applications using this structure. II. The Double-Ended List The double-ended list, or Dlist, is a templated container. It supports the following operational methods: * isEmpty: a predicate that returns true if the list is empty, false otherwise * insertFront/insertBack: insert an object at the front/back of the list, respectively * removeFront/removeBack: remove an object from the front/back of a non-empty list, respectively; throws an exception if the list is empty. Note that while this list is templated across the contained type, T, it inserts and removes only pointers-to-T, not instances of T. This ensures that the Dlist implementation knows that it owns inserted objects, is responsible for copying them if the list is copied, and destroying them if the list is destroyed. The complete interface of the Dlist class is provided in dlist.h. The code is replicated here for your convenience. You may not modify dlist.h in any way. -------------------------------------------------------------- #ifndef __DLIST_H__ #define __DLIST_H__ class emptyList { // OVERVIEW: an exception class }; template <typename T> class Dlist { // OVERVIEW: contains a double-ended list of Objects public: // Operational methods bool isEmpty(); // EFFECTS: returns true if list is empty, false otherwise void insertFront(T *o); // MODIFIES this
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
void insertBack(T *o); // MODIFIES this // EFFECTS inserts o at the back of the list T *removeFront(); // MODIFIES this // EFFECTS removes and returns first object from non-empty list // throws an instance of emptyList if empty T *removeBack(); // MODIFIES this // EFFECTS removes and returns last object from non-empty list // throws an instance of emptyList if empty // Maintenance methods Dlist(); // ctor Dlist(const Dlist &l); // copy ctor Dlist &operator=(const Dlist &l); // assignment ~Dlist(); // dtor private: // A private type struct node { node *next; node *prev; T *o; }; node *first; // The pointer to the 1st node (NULL if none) node *last; // The pointer to the 2nd node (NULL if none) // Utility methods void makeEmpty(); // EFFECT: called by constructors/operator= to establish empty // list invariant void removeAll(); // EFFECT: called by destructor/operator= to remove and destroy // all list elements void copyAll(const Dlist &l); // EFFECT: called by copy constructor/operator= to copy elements // from a source instance l to this instance }; /* Note: this is here *only* because the gnu compiler needs to see the "templatized" versions of your methods. This is the *only* instance in which it is acceptable to #include a cpp file. */ #include "dlist.cpp"
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 9

p5 - Stacks, Queues, and Lists. EECS 280 - Fall 2006 Out...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online