What is Queue ?

( tap to know )

Queue is FIFO(First in First Out) data structure, which means that element inserted first will be removed first. The process to add an element into queue is called "Enqueue" and the process of removal of an element from queue is called "Dequeue".

  • Like stack, queue is also an ordered list of elements of similar data types.

  • Once a new element is inserted into the Queue, all the elements inserted before the new element in the queue must be removed, to remove the new element.

  • peek( ) function is oftenly used to return the value of first element without dequeuing it.

A Real World Example :

  • We Can Use Queue For Processing Network Request In Server.
  • 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. Right? Same is the case with Queue data structure. Data inserted first, will leave the queue first.

Queue may Look Like This :

img