Bag.cpp

Bag.cpp - Winter 2008 CS 32 Project 2 Solution In this...

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

View Full Document Right Arrow Icon
Sheet1 Page 1 Winter 2008 CS 32 Project 2 Solution In this solution, the functions with small, fast implementations are inlined. Alternatively, the inline keyword can be removed an d // Bag.h #ifndef BAG_INCLUDED #define BAG_INCLUDED // Later in the course, we'll see that templates provide a much nicer // way of enabling us to have Bags of different types. For now, we'll // use a typedef. typedef some type ItemType class Bag { public: Bag() bool empty() const int size() const // Return the number of items in the bag. For example, the size // of a bag containing "Clinton", "Clinton", "Clinton", "McCain" is 4. int uniqueSize() const // Return the number of distinct items in the bag. For example, // the uniqueSize of a bag containing "Clinton", "Clinton", "Clinton", // "McCain" is 2. // Insert value into the bag. Return true if the value was // actually inserted. Return false if the value was not inserted // (perhaps because the bag has a fixed capacity and is full). // Remove one instance of value from the bag if present. // Return the number of instances removed, which will be 1 or 0. // Remove all instances of value from the bag if present. // Return the number of instances removed. // Return true if the value is in the bag, otherwise false. // Return the number of instances of value in the bag. // Exchange the contents of this bag with the other one.
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 // Iteration functions void start() void next() bool ended() const int currentCount() const // Housekeeping functions ~Bag() private: // Representation: // a circular doubly-linked list with a dummy node. // m_head points to the dummy node.
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 / 16

Bag.cpp - Winter 2008 CS 32 Project 2 Solution In this...

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