Queue Data Structure using Arrays

In this module, we are going to look upon 

  • What's the core idea behind a queue 
  • Basic operations of a queue
  • Implementation of the queue using array in c++
  • Explanation of code
The queue is a list where insertion is done at one end ( rear ) and deletion is performed at the other end ( front ).

Queue implements FIFO( first in first out ) or LILO( last in last out ) policy. An explanatory video from YouTube.


Fundamental operations :

  1. enqueue ( equivalent to insert ) : data is inserted at rear position
  2. dequeue ( equivalent to delete ) : data is deleted from front position
When an element is enqueued, it takes its place at the rear of the queue, just as a newly arriving customer takes a place at the end of the line. The element dequeued is always the one at the head of the queue, as the customer at the head of the line who has waited for the longest.


Array implementation of queue

Basic operations :

  1. enqueue( x ) : insert element x at the rear end of a queue
  2. dequeue( ) : removes an element from the front end of a queue
  3. frontElement( ) : access the front element of a queue
  4. rearElement( ) : access the rear element of a queue
  5. isEmpty( ) : check whether a queue is empty
  6. size( ) : determines the current size of a queue

Code :


Explanation of code : 




Practice questions

  1. Disk towers ( HackerEarth )
  2. Eerie planet ( HackerEarth )
  3. Monk and chamber of secrets ( HackerEarth )
  4. Queue using two stacks  ( Hackerrank )
  5. Truck tour ( Hackerrank )
In the next module, you will be introduced to double-ended queues (deque )
Any doubt related to the above content can be mentioned in the comment section.

Thank you

Comments