Page 550 - Computer science 868 Class 12
P. 550
Ans. (A–B)/C*(D+E)
=(–AB)/C*(+DE)
=(/–ABC)*(+DE)
=*/–ABC+DE
3. A double ended queue is a linear data structure which enables the user to add and remove integers from either ends i.e., from
front or rear. The details of the class deQueue are given below: [ISC 2023]
Class name : deQueue
Data members/instance variable:
Qrr[] : array to hold integer elements
lim : maximum capacity of the dequeue
front : to point the index of the front end
rear : to point the index of the rear end
Methods/Member functions:
deQueue(int I) : constructor to initialise lim = 1, front = 0 and rear = 0
void add Front(int v) : to add integers in the dequeue at the front end if possible,
otherwise display the message “OVERFLOW FROM FRONT”
void add Rear(int v) : to add integers in the dequeue at the rear end if possible,
otherwise display the message “OVERFLOW FROM REAR”
int popFront() : removes and returns the integers from the front end of the
dequeue if any, else returns-999
int popRear() : removes and returns the integers from the rear end of the
dequeue if any, else returns-999
void show() : displays the elements of the dequeue
(i) Specify the class deQueue giving details of the functions void addFront(int) and int popFront(). Assume that the other
functions have been defined.
The main() function and algorithm need NOT be written.
Ans. class deQueue
{
int Qrr[];
int lim, front, rear;
….
void addFront(int a)
{
if(front==0)
System.out.println(“OVERFLOW FROM FRONT”);
else
Qrr[--front]=a;
}
int popFront( )
{
if(front==rear)
return -999;
else
return Qrr[front++];
}
}
(ii) Differentiate between a stack and a queue. [ISC 2023]
Ans. Stack follows LIFO order where as Queue follows FIFO order.
4. (i) A linked list is formed from the objects of the class given below: [ISC 2023]
Class Node
{
double sal;
Node next;
}
Write and Algorithm OR a Method to add a node at the end of an existing linked list. The method declaration is as follows:
void addNode(Node ptr, double ss)
548548 Touchpad Computer Science-XII

