class LinkedBag
1: // Created by Frank M. Carrano and Timothy M. Henry.
2: // Copyright (c) 2017 Pearson Education, Hoboken, New Jersey.
4: /** ADT bag: Link-based implementation.
5: @file LinkedBag.h
6: Listing 4-3 */
7: #ifndef LINKED_BAG_
8: #define LINKED_BAG_
10: #include "BagInterface.h"
11: #include "Node.h"
13: template<class ItemType>
14: class LinkedBag : public BagInterface<ItemType>
15: {
16: private:
17: Node<ItemType>* headPtr; // Pointer to first node
18: int itemCount; // Current count of bag items
19:
20: // Returns either a pointer to the node containing a given entry
21: // or the null pointer if the entry is not in the bag.
22: Node<ItemType>* getPointerTo(const ItemType& target) const;
23:
24: public:
25: LinkedBag(); // Default constructor
26: LinkedBag(const LinkedBag<ItemType>& aBag); // Copy constructor
27: virtual ~LinkedBag(); // Destructor is virtual
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: }; // end LinkedBag
38: #include "LinkedBag.cpp"
39: #endif