{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

hw4 slon

# hw4 slon - Spring 2009 CS 32 Homework 4 Solution Problem 1...

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

Spring 2009 CS 32 Homework 4 Solution Problem 1 Problem 4 Problem 2 Problem 5 Problem 3 Problem 6 Problem 1: // Multiset.h #ifndef MULTISET_INCLUDED #define MULTISET_INCLUDED #include <algorithm> // for std::swap template #include <cassert> template <typename 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 vakue could be // inserted. (For a linked list representations, 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 the value is in the multiset, otherwise false.

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

View Full Document