Use app×
Join Bloom Tuition
One on One Online Tuition
JEE MAIN 2025 Foundation Course
NEET 2025 Foundation Course
CLASS 12 FOUNDATION COURSE
CLASS 10 FOUNDATION COURSE
CLASS 9 FOUNDATION COURSE
CLASS 8 FOUNDATION COURSE
0 votes
2.4k views
in Computer by (48.9k points)
closed by

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 the front end 

rear: to point to the index of the rear end 

Member functions:

Dequeue(int 1): constructor to initialize the data members lim = 1; front = rear = 0 

void addfront(int val): to add integer from the front if possible else display the message (“Overflow from front”) voidaddrear(intval): to add integer from the rear if 

possible else display the message (“Overflow from rear”) 

int popfront(): returns element from front, if possible otherwise returns – 9999 

int poprear(): returns element from rear, if possible otherwise returns – 9999 

Specify the class Dequeue giving details of the constructor (int), void addfront(int), void addrear (int, popfront ( ) and int poprear ( ). The main function and algorithm need not be written.

Specify the class Dequeue giving details of the constructor (int), 

void addfront(int), void addrear (int, popfront ( ) and int poprear ( ). The main function and algorithm need not be written.

1 Answer

+1 vote
by (49.9k points)
selected by
 
Best answer

public class Dequeue 

int arr[] = new int[100]; 

int lim,front,rear; 

Dequeue(int 1) 

lim=1; 

front=0; 

rear=0; arr=newint[lim]; 

void addfront(int val) 

if(front>0) 

arr[front--]=val;

else

System.out.print("\n Overflow from front"); 

void addrear(int val) 

{

return arr[++front]; 

else 

return -9999; 

int poprear() 

if(front!=rear) 

return arr[rear--]; 

else 

return -9999; 

}

Welcome to Sarthaks eConnect: A unique platform where students can interact with teachers/experts/students to get solutions to their queries. Students (upto class 10+2) preparing for All Government Exams, CBSE Board Exam, ICSE Board Exam, State Board Exam, JEE (Mains+Advance) and NEET can ask questions from any subject and get quick answers by subject teachers/ experts/mentors/students.

Categories

...