0% found this document useful (0 votes)
51 views4 pages

Doubly Linked List. in A Deque, Two Pointers Are Maintained, LEFT and RIGHT, Which Point To

A double ended queue (deque) allows elements to be inserted and deleted from either end in constant time. It is implemented using a circular array or doubly linked list with pointers pointing to both ends. There are two variants: an input restricted deque where insertions can only occur at one end and deletions at both, and an output restricted deque where deletions can only occur at one end and insertions at both. Basic deque operations include insertion and deletion at the front and rear ends.

Uploaded by

usman khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views4 pages

Doubly Linked List. in A Deque, Two Pointers Are Maintained, LEFT and RIGHT, Which Point To

A double ended queue (deque) allows elements to be inserted and deleted from either end in constant time. It is implemented using a circular array or doubly linked list with pointers pointing to both ends. There are two variants: an input restricted deque where insertions can only occur at one end and deletions at both, and an output restricted deque where deletions can only occur at one end and insertions at both. Basic deque operations include insertion and deletion at the front and rear ends.

Uploaded by

usman khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

A double ended queue also called as deque (pronounced as ‘deck’ or ‘dequeue’) is a list in

which the elements can be inserted or deleted at either end in constant time. It is also known
as a head-tail linked list because elements can be added to or removed from either the front
(head) or the back (tail) end. However, no element can be added and deleted from the middle.
In the computer’s memory, a deque is implemented using either a circular array or a circular
doubly linked list. In a deque, two pointers are maintained, LEFT and RIGHT, which point to
either end of the deque. The elements in a deque extend from the LEFT end to the RIGHT end
and since it is circular, in a deque of N elements, Nth element of deque is followed by the first
element of the deque.

There are two variants of a double-ended queue. They include:

 Input restricted deque: In this dequeue,insertions can be done only at one of the
ends,while deletions can be done from both ends.
 Output restricted deque: In this dequeue,deletions can be done only at one of the
ends,while insertions can be done on both ends.

Algorithm Of Dequeue

There are four basic operations in usage of Deque that we will explore:

 Insertion at rear end


 Insertion at front end
 Deletion at front end
 Deletion at rear end

Algorithm for Insertion at rear end

Step-1: [Check for overflow]


if(rear==MAX)
Print("Queue is Overflow”);
return;
Step-2: [Insert Element]
else
rear=rear+1;
q[rear]=no;
[Set rear and front pointer]
if rear=0
rear=1;
if front=0
front=1;
Step-3: return
Algorithm for Insertion at front end

Step-1 : [Check for the front position]


if(front<=1)
Print("Cannot add item at the front”);
return;
Step-2 : [Insert at front]
else
front=front-1;
q[front]=no;
Step-3 : Return

Algorithm for Deletion from front end

Step-1 [ Check for front pointer]


if front=0
print(" Queue is Underflow”);
return;
Step-2 [Perform deletion]
else
no=q[front];
print(“Deleted element is”,no);
[Set front and rear pointer]
if front=rear
front=0;
rear=0;
else
front=front+1;
Step-3 : Return
Algorithm for Deletion from rear end

Step-1 : [Check for the rear pointer]


if rear=0
print(“Cannot delete value at rear end”);
return;
Step-2: [ perform deletion]
else
no=q[rear];
[Check for the front and rear pointer]
if front= rear
front=0;
rear=0;
else
rear=rear-1;
print(“Deleted element is”,no);
Step-3 : Return

You might also like