Bag  0.9
Bag.h
Go to the documentation of this file.
1 // Created by Frank M. Carrano and Tim Henry.
2 // Copyright (c) 2013 __Pearson Education__. All rights reserved.
3 
8 #ifndef _BAG
9 #define _BAG
10 
11 #include "BagInterface.h"
12 
13 template<class ItemType>
14 class Bag : public BagInterface<ItemType>
15 {
16 private:
17  static const int DEFAULT_BAG_SIZE = 6;
18  ItemType items[DEFAULT_BAG_SIZE]; // array of bag items
19  int itemCount; // current count of bag items
20  int maxItems; // max capacity of the bag
21 
22  // Returns either the index of the element in the array items that
23  // contains the given target or -1, if the array does not contain
24  // the target.
25  int getIndexOf(const ItemType& target) const;
26 
27 public:
28  Bag();
29  int getCurrentSize() const;
30  bool isEmpty() const;
31  bool add(const ItemType& newEntry);
32  bool remove(const ItemType& anEntry);
33  void clear();
34  bool contains(const ItemType& anEntry) const;
35  int getFrequencyOf(const ItemType& anEntry) const;
36  vector<ItemType> toVector() const;
37 }; // end Bag
38 
39 #include "Bag.cpp"
40 
41 #endif