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
1.2k views
in Computer by (69.3k points)

Device a representation for a list where insertions and deletions can be made at either end. Such a structure is called a Deque (Double Ended Queue). Write functions for inserting and deleting at either end.

1 Answer

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

Dequeue 

A Dequeue can be represented as follows

Let the total size of elements be n in this Dequeue represented as an array int array[n];

Then 

front = index of the first element 

Rear = index of the last element 

If front = rear then we suppose that the Dequeue is empty

The Dequeue grows from front side till the index of the front becomes 0 and from rear side till the index of the rear equals the array size (n-1).

Now the functions for inserting at the front end of the Dequeue is:-

Insert_front ( int data ) 

{

if ( front == 0 ) 

printf (“Dequeue is full from the front end”); 

else 

{

 front--;

array[front] = data;

}

}

Inserting from the rear end is:- 

insert_rear ( int data )

{

if (rear == n-1) 

printf(“Dequeue is full from rear end”);

else

{

rear++; 

array [ rear ] = data;

}

}

Deleting from the front end: -

int delete_front ()

{

if (front == rear)

printf ( “the Dequeue is empty”);

else

return ( array [ front++ ] );

}

Deleting from the rear end:- 

int delete_rear ()

{

if ( front == rear )

printf(“ the Dequeue is empty ”);

else

return ( array [ rear-- ] );

}

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

...