DS – Dynamic Queue

Dynamic Queue:

  • This size of the queue is not fixed.
  • The size varies depends on insertions and deletions
  • Initially we create the Queue with fixed size.

Creating Queue:

  • We declare the queue pointer variable globally as we use in every function.
  • We perform all queue operations using front and rear pointer variables which are also global.
  • The two other variables we declare called min and curr.
  • “min” represents the initial capacity of Queue.
  • “curr” represents current capacity of Queue.

Logic to Create Queue with specified size:

Insert elements into Queue:

  • We need to check minimum capacity reached or not while inserting elements.
  • We use “rear” pointer to insert elements.
  • When it reaches minimum capacity, we need to increase the block size using realloc() function for further insertions into queue.

Deleting elements from Queue:

  • As we discussed in the static queue, we need to shift all the remaining elements towards front after deletion of Front location element.
  • After deletion of element, we need to decrease the capacity of queue if the current capacity greater than initial capacity.

Display elements of Queue:

Scroll to Top