project2 soln

project2 soln - Project 2 Solution In this solution, the...

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

View Full Document Right Arrow Icon
In this solution, the functions with small, fast implementations are inlined. Alternatively, the inline keyword can be removed and the function definitions moved to Multiset.cpp. (inline will be mentioned at some point in class, so don't worry if you've never seen it before.) // Multiset.h #ifndef MULTISET_INCLUDED #define MULTISET_INCLUDED // Later in the course, we'll see that templates provide a much nicer // way of enabling us to have Multisets of different types. For now, we'll // use a typedef. typedef some type ItemType; class Multiset { public: Multiset(); // Create an empty multiset. bool empty() const; // Return true if the multiset is empty, otherwise false. int size() const; // Return the number of items in the multiset. For example, the size of // a multiset containing "cumin", "cumin", "cumin", "turmeric" is 4. int uniqueSize() const; // Return the number of distinct items in the multiset. For example, // the uniqueSize of a multiset containing "cumin", "cumin", "cumin", // "turmeric" is 2. bool insert(const ItemType& value); // Insert value into the multiset. Return true iff the value could be // inserted. (For a linked list representation, insert always returns // true.) int erase(const ItemType& value); // Remove one instance of value from the multiset if present. // Return the number of instances removed, which will be 1 or 0. int eraseAll(const ItemType& value); // Remove all instances of value from the multiset if present. // Return the number of instances removed. bool contains(const ItemType& value) const; // Return true if value is in the multiset, otherwise false. int count(const ItemType& value) const; // Return the number of instances of value in the multiset. int get(int i, ItemType& value) const; // If 0 <= i < uniqueSize(), copy into value an item in the multiset // and return the number of instances of that item in the multiset. // Otherwise, leave value unchanged and return 0. void swap(Multiset& other); // Exchange the contents of this multiset with the other one. // Housekeeping functions
Background image of page 1

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

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

Page1 / 6

project2 soln - Project 2 Solution In this solution, the...

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

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