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

A simple linear Queue can be implemented using a Dynamic Array, indexed from, sa

ID: 3852890 • Letter: A

Question

A simple linear Queue can be implemented using a Dynamic Array, indexed from, say, k = 0... CAPACITY, where CAPACITY is tracked dynamically on each new entry. [Assume there are front and back indices] a) Write a simple return-function, or statement in C++, called next_index(I), needed to convert this linear Queue into a 'Circular' queue: where, I, is an index of the array. b) What simple formula or statement in C++ in terms of the next_index() function to let the front index to always point to the front element for Dequeueing from the Queue. c) Write the conditional statement, expressed in terms of next_index(), to test the emptiness of the Circular Queue. (d) Using the front and back, write a C++ conditional statement to test when the Queue is full.

Explanation / Answer

a) linear queue initialization:
   Queue()
        {
            front = 0;
            rear = -1;
        }
   circular queue initialization:
         Circular_Queue()
        {
            cqueue_arr = new int [MAX];
            rear = front = -1;
        }
change the front and rear index values to convert the linear queue to circular queue

b) when element will be deleted from the queue, reset the front value to rear so that it should front index to always point the front element.
            if (front == rear)
            {
                front = -1;
                rear = -1;
            }
            else
            {
                if (front == MAX - 1)
                    front = 0;
                else
                    front = front + 1;
            }

C) emptyness test function: at the start assign front and rare to -1;
insert some values into the queue and reassign the front to 0;
and check the condition below for emptyness:

            if (front == -1)
            {
                cout<<"Queue is empty ";
                return;
            }

d) condition statement to test the queue is full:
        
   if ((front == 0 && rear == MAX-1) || (front == rear+1))
            {
                cout<<"Queue is full ";
                return;
            }

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