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* getPointerTo(const ItemType& target) const;
public:
LinkedBag();
LinkedBag(const LinkedBag& aBag); // Copy constructor
virtual ~LinkedBag(); // Destructor should be virtual
int getCurrentSize() const;
bool isEmpty() const;
bool add(const ItemType& newEntry);
bool remove(const ItemType& anEntry);
void clear();
bool contains(const ItemType& anEntry) const;
int getFrequencyOf(const ItemType& anEntry) const;
vector toVector() const;
}; // end LinkedBag
Question 1(10 points)
Consider adding the following constructor to the class LinkedBag:
//This constructor creates a bag object from a given array of entries.
template
LinkedBag::LinkedBag(ItemType items[], int n)
{
itemCount = n;
Node* newNodePtr;
for(int i=0; i(items[i], headPtr);
headPtr = newNodePtr;
}
}
If the parameter array items[] contains the following elements,
Items[]
13
2
9
8
6
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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!