Introduction of Queue Data Structure

By | February 20, 2024

Queue is an ordered list in which all insertions at one end called REAR and deletions are made at another end called FRONT. Queues are sometimes referred to as First In First Out (FIFO) list.

Examples of Queue:
People waiting in line at the bank queue counter from a queue.
In computer, the jobs waiting in line to use processor for execution, this queue is known as Job Queue.

Operations of Queue:
There are two basic queue operations:

  1. Enqueue – It inserts item or element at the rear of the queue. An error occurs if the queue is full.
  2. Dequeue – It removes or deletes an item or element from the front end of the queue, and returns to the user. An error occurs if the queue is empty.

Algorithm to insert an item into Queue:

procedure insertq (item : items) ;
 { add item to the queue q }
 begin
   if rear = n then queue is full
   else begin
   rear := rear + 1 ;
   q[rear] := item ;
 end ;
end ; (of insert q) 

Algorithm to delete an item from Queue:

procedure deleleq (var item : items) ;
 { delete from the front of q and return to user }
 begin 
   if front = rear then queue is empty 
   else begin 
   item := q[front] ;
   front := front + 1 ;
   end ;
end ; (of deletion) 

Application of Queue:
Queue uses First In First Out (FIFO) order, which is good for fair (FIFO) ordering of actions. Application of Queues are:

  • Scheduling processing of GUI events printing request.
  • Simulation orders event models real life queue, i.e., Supermarkets checkout, phone call on hold, etc.

You can watch these two nice videos on Queue Data Structure.

Part-1:

Part-2:

If you would like to contribute, you can also mail your article to raju.cplusplus@gmail.com. Please suggest your improvement for this article if you find anything incorrect.

Author: Mithlesh Upadhyay

I hold an M.Tech degree in Artificial Intelligence (2023) from Delhi Technological University (DTU) and possess over 4 years of experience. I worked at GeeksforGeeks, leading teams and managing content, including GATE CS, Test Series, Placements, C, and C++. I've also contributed technical content to companies like MarsDev, Tutorialspoint, StudyTonight, TutorialCup, and Guru99. My skill set includes coding, Data Structures and Algorithms (DSA), and Object-Oriented Programming (OOPs). I'm proficient in C++, Python, JavaScript, HTML, CSS, Bootstrap, React.js, Node.js, MongoDB, Django, and Data Science.