- It is a linear data structure.
- Using linear queue, we can insert element from one end and remove the elements from another end.
- In double ended queue, we can perform insert and delete operations from both the ends.
- It is also called Deque.
Operations of DEQUE:
- create(): Define and initialize the queue with default values
- isEmpty(): Returns a boolean true value if the queue is empty
- isFull(): Determines whether the queue is full or not with boolean value
- insertFront(): Inserting element at front of Deque
- insertRear(): Insert an element at the rear end of the queue
- deleteRear(): Delete the rear element
- deleteFront(): Delete the front element
- traverse(): Display elements of Queue
| #define size 7|
int front=-1 , rear=-1 ;
- Operating queue from front means – we use ‘front’ variable for insertions and deletions.
- Operating queue from rear means – we use ‘rear’ variable.
Check the Queue is Empty or Not:
Inserting First element and Deleting the Last element:
- We use front and rear variables to represent insertions from Front or Rear locations.
- When the Queue has only one last element then front and read pointing to the same location only.
Queue is Full condition:
If the rear is pointing to last location of queue and we try to insert, then starts inserting elements from the front location.
Function to check the deque is full or not?
if((f==0 && r==si ze-1) || (f == r + 1))
return ((rear+1)%size == front) ;
Way of inserting and deleting elements from both the ends as follows: