Page 519 - Computer science 868 Class 12
P. 519
4. Following is the algorithm to delete an element from the rear end of the Queue.
int deleteRear(int qu[], int max, int front, int rear)
Step 1: Start.
Step 2: If rear = front then display “Empty from rear end..Dequeue Underflow”, return value
Step 3: Decrement rear by 1
Step 4: Return dqu[rear+1]
Step 5: Accept cont
Step 6: If cont=“Yes” or cont=“yes” then go to Step 3
Step 7: Stop.
Let us write the Java code for the above operations.
Program 5 A class called DeQue is defined to perform operations on a Double ended queue. The details
of the class are given below.
Class name : DeQue
Data Members
ele[] : an array to hold integer elements
cap : to store the capacity of the array
front : to point to the index of the front
rear : to point to the index of the rear
Member Functions
DeQue (int max) : constructor to initialise the data members cap = max, front = 0,
rear = 0 and create the integer array
void pushfront(int v) : to add integers from the front index if possible else display
the message “full from front..overflow”
void pushrear(int v) : to add integers from the rear index if possible else display the
message “full from rear..overflow”
int popfront() : to remove and return element from the front, if array is
empty then return -999
int poprear() : to remove and return element from the rear, if array is empty
then return -999
void display() : to display the elements present in the dequeue
Specify the class DeQue giving details of the constructor(int), member functions void
pushrear(int), pushfront(int), int popfront(), int poprear(), and void display().
1 import java.util.*;
2 class DeQue
3 { int ele[],front,rear,cap;
4 DeQue(int max)
5 { cap=max;
6 ele=new int[cap];
7 front=rear=0;
517
Data Structures 517

