Bag  0.91
ArrayBag.h
Go to the documentation of this file.
1 //  Created by Frank M. Carrano and Timothy M. Henry.
2 //  Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
3 
7 #ifndef ARRAY_BAG_
8 #define ARRAY_BAG_
9 
10 #include "BagInterface.h"
11 
12 template<class ItemType>
13 class ArrayBag : public BagInterface<ItemType>
14 {
15 private:
16  static const int DEFAULT_CAPACITY = 6; // Small size to test for a full bag
17  ItemType items[DEFAULT_CAPACITY]; // Array of bag items
18  int itemCount; // Current count of bag items
19  int maxItems; // Max capacity of the bag
20 
21  // Returns either the index of the element in the array items that
22  // contains the given target or -1, if the array does not contain
23  // the target.
24  int getIndexOf(const ItemType& target) const;
25 
26 public:
27  ArrayBag();
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  std::vector<ItemType> toVector() const;
36 }; // end ArrayBag
37 
38 #include "ArrayBag.cpp"
39 #endif