Question: Create a Queue.cnn . Queue.cpp contains the member function implementations for Queue.h . Queue.h = class Queue { public: Queue ( ) ; / /

Create a Queue.cnn. Queue.cpp contains the member function implementations for Queue.h.
Queue.h =
class Queue {
public:
Queue(); // ctor inits a new empty Queue
~Queue(); // dtor erases any remaining QueueItems
void addItem(char* pData);
void removeItem();
void print();
void erase();
private:
QueueItem*_pHead; // always points to first QueueItem in the list
QueueItem*_pTail; // always points to last QueueItem in the list
int _itemCounter; // always increasing for a unique id to assign to each new QueueItem
}; // end definitionclass Queue
The Queue class member functions should not have access to the private members of QueueItem objects. They call the public member functions of QueueItem.
As an example, the outline of the Queue::addItem() member function is shown below. It must add a new QueueItem at the tail of the Queue, and update the _pTail pointer to point to it. The first item placed in the Queue becomes both the head and the tail of the list.:
void Queue::addItem(const char *pData)
{
// dynamically create and init a new QueueItem object
QueueItem *pItem = new QueueItem(pData,++_itemCounter);
if (0==_pHead)// check for empty queue
_pHead =_pTail = pItem;
else
{
// link new item onto tail of list using _pTail pointer
...
}
}
The removeItem() method removes the head QueueItem from the queue, and should release the memory using the C++ delete operator. It updates _pHead to point at the following item (if any) as the new head. If the list becomes empty, both _pHead and _pTail must be set to null (0). It does not change the value of _itemCounter (which is always incremented when a new item is added). If called on an empty Queue, it does nothing.
The erase() method removes all the items in the queue and should release the memory. To implement, you could loop calling removeItem() until the queue is empty.
The Queue destructor should ensure that all items are removed from the queue. The easiest way is to call the erase() method from the destructor.

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 Databases Questions!