

The easiest way of implementing a queue is by using an Array. Queue can be implemented using an Array, Stack or Linked List. The interrupts are handled in the same order as they arrive i.e First come first served.

Queue, as the name suggests is used whenever we need to manage any group of objects in an order in which the first one coming in, also gets out first while the others wait for their turn, like in the following scenarios:
#Enqueue vs dequeue movie
If you go to a ticket counter to buy movie tickets, and are first in the queue, then you will be the first one to get the tickets. Which is exactly how queue system works in real world.

This makes queue as FIFO(First in First Out) data structure, which means that element inserted first will be removed first. Container Type of the internal underlying container object where the elements are stored.Īliased as member type queue::container_type.Queue is also an abstract data type or a linear data structure, just like stack data structure, in which the first element is inserted from one end called the REAR(also called tail), and the removal of existing element takes place from the other end called as FRONT(also called head).īefore you continue reading about queue data structure, check these topics before to understand it clearly: Template parameters T Type of the elements.Īliased as member type queue::value_type. By default, if no container class is specified for a particular queue class instantiation, the standard container deque is used. The standard container classes deque and list fulfill these requirements. This underlying container shall support at least the following operations: The underlying container may be one of the standard container class template or some other specifically designed container class.

Elements are pushed into the "back" of the specific container and popped from its "front". Queues are implemented as containers adaptors, which are classes that use an encapsulated object of a specific container class as its underlying container, providing a specific set of member functions to access its elements. FIFO queue queues are a type of container adaptor, specifically designed to operate in a FIFO context (first-in first-out), where elements are inserted into one end of the container and extracted from the other.
