Queue





Definition: A collection of elements that are stored next to each other in a line. Elements can only be inserted at one side of the structure and only deleted from the other side. This can be referred to simply by the phrase "first in, first out".



Real Life Example: Imagine that you are at a playground. Your friends Tom, Bob, and Bill all go down a slide in that order, one after the other. Because Tom went down first, he will be the first person to exit the slide. After him will be Bob and the last to exit will be Bill because he was the last to enter.


Note: The first element in a queue (closest to being removed) is referred to as the "front". The last element in a queue (most recent insertion) is referred to as the "rear" or "back".



Basic Queue Operations:

  1. Enqueuing (a.k.a offering) an element. An element is added to the queue at the rear.
  2. Dequeuing (a.k.a polling) an element. The front-most element is removed from the queue.


Fun Fact: Have you created a Youtube playlist before? If so, you have used a queue! The first video added to a playlist is the first one played (first in first out) and the last video added is the last one played (last in last out).



Commonly Used In:



Other Similar Data Structures: