Photo by Macau Photo Agency on Unsplash

Queue Data Structure: Practical Applications & Operations

Learn how queues are used in real applications and it’s implementation in Python and C++

Watch the video version if you prefer that !

Practical Applications

So what makes queues special ? A queue is a data structure that follows First In First Out — which means the first item to enter the queue is the first to leave the queue.

  • Message Queues – A message queue is a general concept used for communication between processes. Basically a sender sends a message, and if the receiver cannot receive it immediately maybe because it is busy with something or offline, the message instead of dropping off, waits in some kind of a queue, and when the receiver is ready to receive it, the message is consumed or removed from the queue and sent to the receiver.
    For example, when you send an email, it waits in a queue called the SMTP queue, until the receiver logs into their inbox. Same concept is applied when you send a message to someone who is not online on a social network. Your message waits in some kind of a queue on a server, and when the recipient comes online, it is sent to them.
  • Process Scheduling – All the processes running on your computer now, first wait in a queue called ready queue, waiting to be executed by your processor. There are various scheduling algorithms that decide which process should be executed next based on certain criteria like priority.
  • Data Buffers – A buffer implements a queue and is typically used in communication when there is difference between the rate at which data is received and the rate at which it can be processed.
    For example in video streaming applications, the video is streamed in bursts and stored in a buffer so that even if the network becomes slow for a while, the playback is not interrupted. Say for example the video is playing at 24fps, then the streaming app may store 240 frames in its buffer, so that it can continue playing for the next 10 seconds even if the network is interrupted. The buffer is also used for sequencing frames, ie, if frames come out of order, they are sorted in the buffer before being played. Buffers also used in disk drives, input/output devices and communication over networks.
  • It is also used in several algorithms like the Breadth First Search or BFS algorithm, and round robin algorithm.

Queue Operations

Queue operations
  • Enqueue – adding an element to a queue is called enqueuing. The new element is usually added to the back of the queue. In the example, 10 is enqueued, and added to the queue.
  • Dequeue – removing an element from a queue is call dequeue. On calling dequeue, the element from the front of the queue (more generally, the opposite end where enqueue was performed) is removed. In the example, 15 is at the front, and on dequeuing it is removed and the value is returned.
  • Front – this function simply returns the value at the front of the queue. This will be the element that will be dequeued next.
  • Back/Rear – this function returns the value at the back of the queue. This will be the element that was just added to the queue.

Implementing Queue

Here are common implementations of queue in Python and C++, especially useful if you are preparing for coding interviews.


In python the inbuilt list data structure can be used to implement a queue.


In C++, the STL (Standard Template Library) already has an implementation of queue.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store