Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Define a function removeAll that removes all the first occurrence of an item in a circular queue without changing the order of the other elements

Define a function removeAll that removes all the first occurrence of an item in a circular queue without changing the order of the other elements in the queue. Use the following header:

template

void queueType::removeAll (queueType& Q, const Type& x)

Answer:

template

void queueType::removeAll(queueType& Q, const Type& x)

{

assert(!Q.isEmptyQueue());

int m = Q.queueFront;

bool found = false;

while (m<=Q.queueFront+Q.count-1 && !found)

{

if (Q.list[m%Q.maxQueueSize] == x)

{

found = true;

if (m%Q.maxQueueSize != Q.queueRear)

{ // you do not want to move items if you are at the end

for (int n=m%Q.maxQueueSize; n

{

Q.list[n%Q.maxQueueSize] = Q.list[(n+1)%Q.maxQueueSize];

}

}

Q.count--; // you have deleted an item

Q.queueRear--; // so update count and queueRear

if (Q.queueRear<0)

{

Q.queueRear = Q.maxQueueSize-1;

}

}

m++; // move to next item in the queue

}

}

Question: Would this template function remove all the occurences of the item?

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions