Menu Close

Double ended queue in c

Deque:

  • 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:

  1. create(): Define and initialize the queue with default values
  2. isEmpty(): Returns a boolean true value if the queue is empty
  3. isFull(): Determines whether the queue is full or not with boolean value
  4. insertFront(): Inserting element at front of Deque
  5. insertRear(): Insert an element at the rear end of the queue
  6. deleteRear(): Delete the rear element
  7. deleteFront(): Delete the front element
  8. traverse(): Display elements of Queue

Declaration:

	#define size 7
	int deque[size];
	int front=-1 , rear=-1 ;

Notes:

  • Operating queue from front means – we use ‘front’ variable for insertions and deletions.
  • Operating queue from rear means – we use ‘rear’ variable.

Empty Queue:

  • 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.