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

Info icon This 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:
Image of page 1

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

View Full Document Right 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(const Dlist &l) Dlist &operator=(const Dlist &l) ~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)
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" #endif /* __DLIST_H__ */ -------------------------------------------------------------- The definition of "node", the private type for elements of the container list, is given in the private section of class Dlist. This is so that clients of the class cannot use the type.
Image of page 3

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

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

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern