mayukh datta

Queue is a linear data structure like stack and linked list. It follows FIFO (First-in, First-out) or LILO (Last-in, Last-out) policy. It has two main operations - enqueue (insert element; can only be inserted at the rear of a queue) and dequeue (remove element; can only be removed from the front of a queue).

queue-data structure

I have four USB storage devices each containing some data that I need to copy to hard drive. As an USB port can read data from a single device at a time, so I have organized them in a queue such that each device is served one after the other. Now as queue basically follows "First Come, First Serve" rule, therefore the device with index 0 being the first device to be placed in the queue must be served first and the last placed device with index 3 must be served at the last. This is how queue follows FIFO policy.

Like stack, queue can also be implemented by array and linked list.

Code for simple array implementation of queue:-

We have used array in simple and usual manner to implement queue but it might not be the efficient. We can't insert elements into rooms of array where deletion operation took place earlier, therefore memory gets wasted. To learn in details, watch this. So, it would be better to use array in a circular manner where first and last elements are contiguous.

Code for circular array implementation of queue:-

I'm still working on the code for linked list implementation of queue. I'll update this post with it as soon as I complete it. Double-ended queue and priority queue will be discussed later on.


  1. U made it so interesting and easy👍

    1. Thanks, mam. I'm glad that you read maximum of my blogs every time.😌💚

  2. Thanks, mam. I'm glad that you read maximum of my blogs every time.😌💚


Post a Comment