Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am really confused with this queue example, it seem s easy but yet I am struggling to figure it out. Please help. Download the

I am really confused with this queue example, it seem s easy but yet I am struggling to figure it out. Please help.

Download the file Queue.zip and modify the Queue.cpp file by implementing the details for the helper function called highPriority(), which will take the in a queue and an item as parameters, and will insert the item at the front of the queue. The remaining items in the queue will remain unchanged. The prototype for this function is as follows:

template void highPriority(queue &myQueue, Object item);

Hint: Again, you only need to modify the areas in the Queue.cpp file by adding the necessary code to implement the TODO areas as noted in the comments. The prototype for the function and everything else in the program will remain unchanged. You must use the function signature for your implementation. Consider using another queue called results to hold the results as you are processing the items in the queue:

queue results;

Start by adding the passed in item to the results queue by calling results.push(item). Then walk through the queue, which is the passed in myQueue variable using a while loop like the one in the printQueue() function. Add the tmpItem to the queue by calling the push() function on the results queue. Before returning from function, set myQueue equal to the results queue:

myQueue = results;

Output: The output for the program after the function is implemented should appear as follows:

Queue: 26 17 86 90 15

Queue after inserting 30:

30 26 17 86 90 15

Queue after inserting 85: 85 30 26 17 86 90 15

Queue after inserting 77: 77 85 30 26 17 86 90 15

** Press any key to continue **

Below is the queue file that needs adjusting. The high priority is the only class/template that needs to be implemented.

/** * Queue.cpp - This program implements and tests the * addToFront() helper funciton. * * */

#include #include #include

using namespace std;

template void printQueue(queue myQueue);

template void highPriority(queue &myQueue, Object item);

int main(int argc, char **argv) { // Declare queue variables queue myQueue;

// Add some data to queue 1 myQueue.push(26); myQueue.push(17); myQueue.push(86); myQueue.push(90); myQueue.push(15);

cout printQueue(myQueue);

cout highPriority(myQueue, (int)30); printQueue(myQueue);

cout highPriority(myQueue, (int)85); printQueue(myQueue);

cout highPriority(myQueue, (int)77); printQueue(myQueue);

cout getchar();

system("pause"); return 0; }

template void printQueue(queue myQueue) { queue tmpQueue = myQueue; Object tmpItem; while (!tmpQueue.empty()) { tmpItem = tmpQueue.front();

cout

tmpQueue.pop(); }

cout

return; }

template void highPriority(queue &myQueue, Object item) { // TODO: Implement the details for the highPriority function.

return; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Combinatorial Testing In Cloud Computing

Authors: Wei-Tek Tsai ,Guanqiu Qi

1st Edition

9811044805, 978-9811044809

More Books

Students also viewed these Programming questions

Question

What is an intranet?

Answered: 1 week ago

Question

What is client/server computing?

Answered: 1 week ago