Question: template class LinkedBag : public BagInterface { private: Node * headPtr; / / Pointer to first node int itemCount; / / Current count of bag
template
class LinkedBag : public BagInterface
private:
Node headPtr; Pointer to first node
int itemCount; Current count of bag items
Returns either a pointer to the node containing a given entry
or the null pointer if the entry is not in the bag.
Node getPointerToconst ItemType& target const;
public:
LinkedBag;
LinkedBagconst LinkedBag& aBag; Copy constructor
virtual ~LinkedBag; Destructor should be virtual
int getCurrentSize const;
bool isEmpty const;
bool addconst ItemType& newEntry;
bool removeconst ItemType& anEntry;
void clear;
bool containsconst ItemType& anEntry const;
int getFrequencyOfconst ItemType& anEntry const;
vector toVector const;
; end LinkedBag
Question points
Consider adding the following constructor to the class LinkedBag:
This constructor creates a bag object from a given array of entries.
template
LinkedBag::LinkedBagItemType items int n
itemCount n;
Node newNodePtr;
forint i; iitemsi headPtr;
headPtr newNodePtr;
If the parameter array items contains the following elements,
Items
what does the linked list of the bag object created by this constructor look like?
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
