Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

write a function truncate for a queue data structure. The element in the queue c

ID: 3582876 • Letter: W

Question

write a function truncate for a queue data structure. The element in the queue contains an Int-type variable called x. the truncate function starts from the first element and searches all remaining elements in the queue. once it finds an element repeating x it removes it. once the truncate function has ensured that an element is not repeated it processes it by printing it write a function truncate for a queue data structure. The element in the queue contains an Int-type variable called x. the truncate function starts from the first element and searches all remaining elements in the queue. once it finds an element repeating x it removes it. once the truncate function has ensured that an element is not repeated it processes it by printing it write a function truncate for a queue data structure. The element in the queue contains an Int-type variable called x. the truncate function starts from the first element and searches all remaining elements in the queue. once it finds an element repeating x it removes it. once the truncate function has ensured that an element is not repeated it processes it by printing it

Explanation / Answer

FUNCTION:

void truncate_Queue(int info){
int i;
if ((FRONT==-1) && (REAR==-1))
{
printf(" Queue is empty i.e. no elements in queue to delete");
return;
}

for (i = 0; i <= REAR; i++)
{ if (info == Queue[i])
{for (; i < REAR; i++)
{ Queue[i] = Queue[i + 1];
}
Queue[i] = -99;
REAR--;
if (REAR == -1)
FRONT = -1;
return;
}
}
   if ((FRONT == -1) && (REAR == -1))
{
printf(" Empty Queue ");
return;
}

for (; FRONT <= REAR; FRONT++)
{
printf(" %d ", Queue[FRONT]);
}

FRONT = 0;
printf(" %d not found in queue to delete", info);
   }