Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 addItemchar pData;
void removeItem;
void print;
void erase;
private:
QueueItempHead; always points to first QueueItem in the list
QueueItempTail; 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::addItemconst char pData
dynamically create and init a new QueueItem object
QueueItem pItem new QueueItempDataitemCounter;
if 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 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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started