Page 552 - Computer science 868 Class 12
P. 552
7. (a) A Circular queue is a linear data structure which works on the principle of FIFO, enables the user to enter data from the rear
end and remove data from the front end with the rear end connected to the front end to form a circular pattern. Define a
class CirQueue with the following details:
Class name : CirQueue
Data Member/Instance variable
cq[] : array to store the integers
cap : stores the maximum capacity of the array
front : to point the index of the front end
rear : to point the index of the rear end
Member Functions/Methods
CirQueue (int max) : constructor to initialize the data member cap=max, front=0 and rear=0
void push(int n) : to add integer in the queue from the rear end if possible, otherwise display
the message “QUEUE IS FULL”
int pop() : removes and returns the integer from the front end of the queue if any, else
returns - 9999
void show() : displays the queue elements
Specify the class CirQueue giving details of the functions void push(int) and int pop(). Assume that the other functions have
been defined. The main function and algorithm need NOT be written. [ISC 2020]
Ans. class CirQueue
{
void push(int v)
{
if( (rear+1)% cap !=front)
{
rear = (rear + 1)% cap ;
cq[rear] =v;
}
else
System.out.println(" QUEUE IS FULL");
}
int pop()
{
if (front != rear)
{
front = ( front + 1)% cap ;
return cq[front];
}
else
return -9999;
}
}
(b) How is a linear queue structure different from a circular queue structure? [ISC 2020]
Ans. In linear queue, insertion is done from the rear end, and deletion is done from the front end. In circular queue, the insertion and
deletion can take place from any end.
8. (a) A linked list is formed from the objects of the class Node. The class structure of the Node is given below: [ISC 2020]
class Node
{
int n;
Node next;
}
Write an Algorithm OR a Method to find the product of the integer numbers from an existing linked list.
The method declaration is as follows:
void Product_Node( Node str )
Ans. ALGORITHM
Step 1: Start
550550 Touchpad Computer Science-XII

