- 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 deque[size]; 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.
- Inserting elements into deque as follows:
- Initially front and rear variables pointing to no index.
- After insertion of first element either using front or rear, both are start pointing to 0 index.
- When front and rear values are equal, then the deque has only one last element to be deleted.
- After deleting the last element either from front or rear, the values assigned to -1 to make the deque is empty.
- After inserting the first element, if we keep on inserting elements using rear by increasing rear value, it reaches Queue is Full condition as shown in the diagram.
- When we try to insert the element from front and the front is not empty, index moves to the last location of deque.
- The following diagram gives another values of “Queue is Full” condition.
- The elements will be deleted exactly with the opposite direction in which elements are inserted.
- The following diagram represents deletion.