Question: C++ programming Visual studio (software used) in this Queue.cpp part. (hit: inside the queue. h there are class function and one struct inside the private

C++ programming Visual studio (software used)

in this Queue.cpp part. (hit: inside the queue. h there are class function and one struct inside the private class. I added the screenshot of the header file in case you need to look at it) C++ programming Visual studio (software used) in this Queue.cpp part. (hit: inside

I am trying to replace the array-based queue module with a queue based upon a singly linked list.

this is my work code please check if there is something to add and correct.

/*--------------- E n q u e u e ( ) --------------

PURPOSE

Add an item to the tail of the queue.

INPUT PARAMETER

elem -- the item to add

*/

void Queue::Enqueue(QueueElem &elem)

{

Node *newNode = new(nothrow) Node; // creat a new node

// Prevent queue overflow.

assert(newNode != NULL);

// Add the new item to the tail and update the tail index and size.

newNode->data = elem;

newNode->succ = head;

newNode->succ = tail;

head = newNode;

tail = newNode;

}

/*--------------- D e q u e u e ( ) --------------

PURPOSE

Remove and return the head item from the queue.

*/

QueueElem Queue::Dequeue()

{

// Insure not empty.

assert(!Empty());

head = head->succ;

tail = tail->succ;

// Capture the head item data, update the head index and size.

QueueElem elem = head->data;

// Return the old head data.

return elem;

}

/*--------------- H e a d ( ) --------------

PURPOSE

Return but do not remove the head item from the queue.

*/

QueueElem Queue::Head()

{

// Insure not empty.

assert(!Empty());

// Return the head item data.

return head->data;

}

Queuecpp Queue:11 typedef Position QueueEle; The queue stores maze row/colunns positions arch Solution txplorer (Ctrl :) 23 4 const unsipQueuecap-10; / Maximum queue entries 25 26 27 28 Salution Progs project) cl as s Qeue DErternal Dependencies Header Hles //Define a generic queue class class Queue private: Mazeh 30 b Rosition.h 32 /I list node class definition struct Node Resource riles Scurce Files bCurscrCntlcpp ++ Maze cpp 36 37 38 QueueElem data; // The "contents" of the node Node succ; ink to the successor node Prog.rpp Node Constructor urictions Node() succ(a) 0 Node(const Queuetlem &theData) 48 data(theData), succ(e) tJ olution Explorer public: I Constructor: Create empty queue Queue) : head(e), tail(0) // Return true if queue empty bool Fmpty) costreturn heade I Enqueue a new entry to the tail void EnquQcEle clm); 1 Dequeue the head entry QueueElem Deqeue) 45 51 52 Retrieve the head entry Queuetlem Head private: Node *head Node tail; oueueflem aueuerOueuecanl: Queue stored here 0% Ready Ln 31 Col 2 Ch 2 Add to Source Control Queuecpp Queue:11 typedef Position QueueEle; The queue stores maze row/colunns positions arch Solution txplorer (Ctrl :) 23 4 const unsipQueuecap-10; / Maximum queue entries 25 26 27 28 Salution Progs project) cl as s Qeue DErternal Dependencies Header Hles //Define a generic queue class class Queue private: Mazeh 30 b Rosition.h 32 /I list node class definition struct Node Resource riles Scurce Files bCurscrCntlcpp ++ Maze cpp 36 37 38 QueueElem data; // The "contents" of the node Node succ; ink to the successor node Prog.rpp Node Constructor urictions Node() succ(a) 0 Node(const Queuetlem &theData) 48 data(theData), succ(e) tJ olution Explorer public: I Constructor: Create empty queue Queue) : head(e), tail(0) // Return true if queue empty bool Fmpty) costreturn heade I Enqueue a new entry to the tail void EnquQcEle clm); 1 Dequeue the head entry QueueElem Deqeue) 45 51 52 Retrieve the head entry Queuetlem Head private: Node *head Node tail; oueueflem aueuerOueuecanl: Queue stored here 0% Ready Ln 31 Col 2 Ch 2 Add to Source Control

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!