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

Write a function that enqueues a node in a circular queue. void Queue: enqueue(i

ID: 3797085 • Letter: W

Question

Write a function that enqueues a node in a circular queue. void Queue: enqueue(int value); If the queue is full print out "Queue Full" and return; The function is a member of a class called Queue. Write the function definition only for enqueue. Given below is the class definition: class cQueue {public: cQueue(int max); virtual ~cQueue(); void enqueue(int value); int getTail(); void displayQueue(); protected: private: int *c_array; int head; int tail; int size;}; Head and Tail are initialized as follow: head = -1; tail = -1;

Explanation / Answer

Hi, please find my implementation of 'enqueue' method.

please let me know in case of any issue.

void enqueue(int value){
cout<<"Enqueuing "<<value<<" ";
if((tail+1)%size == head)
{
cout<<"Error: Queue is Full ";
return;
}
// calculating tail value where we have to store the value
if (head == -1 && tail == -1) // queue is empty then initialize head and tail with 0
{
head = tail = 0;
}
else
{
tail = (tail+1)%size; // increasing tail in circular fashion
}

c_array[tail] = value;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote