p5 - Stacks and Queues and Lists, Oh My! EECS 280 - Winter...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 Stacks and Queues and Lists, Oh My! EECS 280 -- Winter 2008 Out Wednesday, March 26th. Due: Tuesday, April 15th, 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 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:
Background image of page 1

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

View Full DocumentRight Arrow Icon
Sheet1 Page 2 // Operational methods bool isEmpty() // EFFECTS: returns true if list is empy, false otherwise void insertFront(T *o) // MODIFIES this // EFFECTS inserts o at the front of the list 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() ~Dlist() private: // A private type struct node { node *next node *prev T *o } node *first node *last // 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)
Background image of page 2
Sheet1 Page 3 // REQUIRES: this list is empty // 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 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

Page1 / 20

p5 - Stacks and Queues and Lists, Oh My! EECS 280 - Winter...

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

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