Page 625 - Computer science 868 Class 12
P. 625
Program 21 Double-Ended Queue
Double-Ended Queue is a special form of Queue. It is a double-ended queue, in which a data
can be added or removed at either end. However, in a double-ended queue, neither data can
be inserted nor can be removed from random positions.
Design a class Dqueue to implement double queue concept using an array given the following
class description:
Data Members
int ar[] : Array to implement queue
int f : Stores the front position of the array
int r : Stores the rear position of the array
int size : Stores the size of the queue
Member Functions
Dqueue(int) : Parameterised constructor to input array size
void addrear(int) : To enter an element at rear in the queue
void deletefront() : To remove an element from the front in the queue
void addfront(int) : To enter an element at front in the queue
void deleterear() : To remove an element from rear in the queue
void display() : To display the queue
1 import java.util.*;
2 class Deque
3 {
4 int a[];
5 intf,r,n;
6 dque(int x)
7 {
8 n=x;
9 a = new int[n];
10 f = r = -1;
11 }
12 void addrear(int x)
13 {
14 if(f<=r&&r<n-1)
15 {
16 a[++r]=x;
17 }
18 else
19 {
20 System.out.println("Queue full");
21 }
623
Internal Assessment 623

