CISC 2200 Project 2
VectorBag.h
Go to the documentation of this file.
1 
15 #ifndef _VECTOR_BAG
16 #define _VECTOR_BAG
17 
18 #include "BagInterface.h"
19 
24 template<class ItemType>
25 class VectorBag: public BagInterface<ItemType>
26 {
27 public:
28  int getCurrentSize() const;
29  bool isEmpty() const;
30  bool add(const ItemType& newEntry);
31  bool remove(const ItemType& anEntry);
32  void clear();
33  bool contains(const ItemType& anEntry) const;
34  int getFrequencyOf(const ItemType& anEntry) const;
35  vector<ItemType> toVector() const;
36 
44 
50 
57 
58 private:
59  vector<ItemType> items; // where we store the bag
60  // Returns either the index of the element in the array items that
61  // contains the given target or -1, if the array does not contain
62  // the target.
63  int getIndexOf(const ItemType& target) const;
64 
65 }; // end VectorBag
66 
67 #include "VectorBag.cpp"
68 #endif
bool contains(const ItemType &anEntry) const
Tests whether this bag contains a given entry.
Definition: VectorBag.cpp:71
VectorBag< ItemType > operator*(VectorBag< ItemType > anotherBag)
Creates a new bag that contains those objects that occur in both this bag and a second given bag with...
Definition: VectorBag.cpp:101
CISC 2200: Data Structures Project 2: Extending the Bag ADT
Listing 1-1.
vector< ItemType > toVector() const
Empties and then f ills a given vector with all entries that are in this bag.
Definition: VectorBag.cpp:80
int getCurrentSize() const
Gets the current number of entries in this bag.
Definition: VectorBag.cpp:18
int getFrequencyOf(const ItemType &anEntry) const
Counts the number of times a given entry appears in bag.
Definition: VectorBag.cpp:59
VectorBag< ItemType > operator-(VectorBag< ItemType > anotherBag)
Creates a new bag of objects that would be left in this bag after removing those that also occur in a...
Definition: VectorBag.cpp:109
VectorBag< ItemType > operator+(VectorBag< ItemType > anotherBag)
Creates a new bag that combines the contents of this bag and a second given bag without affecting the...
Definition: VectorBag.cpp:87
bool add(const ItemType &newEntry)
Adds a new entry to this bag.
Definition: VectorBag.cpp:30
VectorBag is a vector-based implementation of BagInterface.
Definition: VectorBag.h:25
Definition: BagInterface.h:13
bool isEmpty() const
Sees whether this bag is empty.
Definition: VectorBag.cpp:24
void clear()
Removes all entries from this bag.
Definition: VectorBag.cpp:53