In DEQUE, insertion and deletion operations are performed at both ends of the Queue.

Exceptional Condition of DEQUE
- Input Restricted DEQUE
Here insertion is allowed at one end and deletion is allowed at both ends.
Deletion
Insertion

Front Rear
- Output Restricted DEQUE
Here insertion is allowed at both ends and deletion is allowed at one end.
Insertion Deletion

Front Rear
Operations on DEQUE
Four cases for inserting and deleting the elements in DEQUE are
- Insertion At Rear End [ same as Linear Queue
- Insertion At Front End
- Deletion At Front End [ same as Linear Queue ]
- Deletion At Rear End

Case 1: Routine to insert an element at Rear end
void Insert_Rear (int X, DEQUE DQ)
{
if( Rear = = Arraysize – 1)
Error(“Full Queue!!!! Insertion not possible”); else if( Rear = = -1)
{
Front = Front + 1; Rear = Rear + 1; DQ[ Rear ] = X;
}
else
{
Rear = Rear + 1; DQ[ Rear ] = X;
}
}

Case 2: Routine to insert an element at Front end
void Insert_Front ( int X, DEQUE DQ )
{
if( Front = = 0 )
Error(“Element present in Front!!!!! Insertion not possible”); else if(Front = = -1)
{
Front = Front + 1; Rear = Rear + 1; DQ[Front] = X;
}
else
{
Front = Front – 1; DQ[Front] = X;
}
}

Case 3: Routine to delete an element from Front end
void Delete_Front(DEQUE DQ)
{
if(Front = = – 1)
Error(“Empty queue!!!! Deletion not possible”); else if( Front = = Rear )
{
X = DQ[ Front]; Front = – 1; Rear = – 1;
}
else
{
X = DQ [ Front ]; Front = Front + 1;
}
}


Case 4: Routine to delete an element from Rear end
void Delete_Rear(DEQUE DQ)
{
if( Rear = = – 1)
Error(“Empty queue!!!! Deletion not possible”); else if( Front = = Rear )
{
X = DQ[ Rear ];
Front = – 1; Rear = – 1;
}
else
{
X = DQ[ Rear ];
Rear = Rear – 1;
}
}


