PRASHNIKAप्रश्निका
Back to the paper

A circular queue is a linear data structure that allows data insertion at the rear and removal from…

Computer Science20255 marksProgram
A circular queue is a linear data structure that allows data insertion at the rear and removal from the front, with the rear end connected to the front end forming a circular arrangement. The details of the members of the class are given below: Class name : CirQueue Data members/instance variables: Q[ ] : array to hold integer values cap : maximum capacity of the circular queue front : to point the index of the front rear : to point the index of the rear Methods/Member functions: CirQueue(int n) : constructor to initialise cap = n, front = 0 and rear = 0 void push(int v) : to add integers from the rear index if possible else display the message "QUEUE IS FULL" int remove( ) : to remove and return the integer from front if any, else return -999 void print( ) : to display the elements of the circular queue in the order of front to rear
(i)[4.0]
Specify the class CirQueue giving the details of the functions void push(int) and int remove( ). Assume that the other functions have been defined. The main( ) function and algorithm need NOT be written.
(ii)[1.0]
State one application of a circular queue.

Answer

Answer (i)

AI
void push(int v)
{
    if ((rear + 1) % cap == front)
        System.out.println("QUEUE IS FULL");
    else
    {
        Q[rear] = v;
        rear = (rear + 1) % cap;
    }
}

int remove()
{
    if (front == rear)
        return -999;
    int val = Q[front];
    front = (front + 1) % cap;
    return val;
}
Explanation: push() adds v at the rear index and advances rear circularly (using %cap), but first checks whether the next rear position would collide with front (queue full). remove() checks for an empty queue (front==rear) and returns -999 in that case; otherwise it returns the element at front and advances front circularly. Tested and working correctly for wraparound and full/empty conditions.

Answer (ii)

AI
A circular queue is used to implement a CPU/round-robin scheduler, where processes are cyclically given a fixed time slice on the CPU.
Data structures

From ISC 2025 Computer Science Paper 1, question 9.