Question
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
Answer:
template
void queueType
{
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
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