Project 2
Bag.hpp
Go to the documentation of this file.
1 // Based on code from Frank M. Carrano and Tim Henry.
2 
6 #ifndef BAG_HPP
7 #define BAG_HPP
8 
9 #include <vector>
10 #include "Node.hpp"
11 
12 template<class ItemType>
13 class Bag
14 {
15 private:
16  Node<ItemType>* headPtr; // Pointer to first node
17  int itemCount; // Current number of items in bag
18 
22  Node<ItemType>* getPointerTo(const ItemType& target) const;
23 
24 public:
26  Bag();
28  ~Bag();
31  int size() const;
34  bool isEmpty() const;
40  bool add(const ItemType& newEntry);
43  void clear();
47  bool contains(const ItemType& anEntry) const;
51  int getFrequencyOf(const ItemType& anEntry) const;
55  std::vector<ItemType> toVector() const;
56 }; // end Bag
57 
58 // Include the source for the template class
59 #include "Bag.cpp"
60 
61 #endif
Bag()
Definition: Bag.cpp:10
bool add(const ItemType &newEntry)
Definition: Bag.cpp:27
Definition: Node.hpp:8
std::vector< ItemType > toVector() const
Definition: Bag.cpp:100
~Bag()
Definition: Bag.cpp:116
void clear()
Definition: Bag.cpp:40
Definition: Bag.hpp:13
int size() const
Definition: Bag.cpp:15
int getFrequencyOf(const ItemType &anEntry) const
Definition: Bag.cpp:80
bool contains(const ItemType &anEntry) const
Definition: Bag.cpp:74
bool isEmpty() const
Definition: Bag.cpp:21