C Programs Tutorials | IT Developer
IT Developer

Java Programs - Solved 2013 Theory Paper ISC Computer Science



Share with a Friend

Solved 2013 Theory Paper ISC Computer Science

Class 12 - ISC Computer Science Solved Theory Papers

Dequeue Queue Program - ISC 2013 Theory

A doubly queue is a linear data structure which enables the user to add and remove integers from either ends, i.e. from front or rear. Define a class Dequeue with the following details:

Class name: Dequeue
Data members/instance variables:
arr[ ]: array to hold up to 100 integer elements.
lim: stores the limit of the dequeue.
front: to point to the index of front end.
rear: to point to the index of rear end.

Member functions:
Dequeue(int l): constructor to initialize data members lim = l; front = rear = 0.
void addFront(int val): to add integer from the front if possible else display the message “Overflow from front”.
void addRear(int val): to add integer from the rear if possible else display the message “Overflow from rear”.
int popFront(): returns element from front if deletion is possible from the front end, otherwise returns -9999.
int popRear(): returns element from rear if deletion is possible from the rear end, otherwise returns -9999.

Specify the class Dequeue giving details of the constructor, void addFront(int), void addRear(int), int popFront() and int popRear().

The main function and algorithm need not be written.

class Dequeue{ int arr[]; int lim; int front; int rear; public Dequeue(int l){ lim = l; front = 0; rear = 0; } public void addFront(int val){ if(front - 1 >= 0) arr[--front] = val; else System.out.println("Overflow from front"); } public void addRear(int val){ if(rear + 1 < lim) arr[++rear] = val; else System.out.println("Overflow from rear"); } public int popFront(){ if(front + 1 <= rear) return arr[front--]; return -9999; } public int popRear(){ if(rear - 1 >= front) return arr[rear--]; return -9999; } }

Output

 
OUTPUT :