SlideShare a Scribd company logo
4
Most read
5
Most read
8
Most read
Queue Data Structure
A queue is open at both its ends. One end is always used to
insert data (enqueue) and the other is used to remove data
(dequeue).
 Queue follows First In First Out (FIFO) methodology, i.e., the
data item stored first will be accessed first.
It has two pointers – front and rear. Front is used for deletion
and rear is used for insertion.
The difference between stack and queue is in removing the
elements. In a stack we remove the item that has been recently
added but in a queue, we remove the item that has been added
at the first.
EXAMPLES OF QUEUE
OPERATIONS OF QUEUE
Insertion/Enqueue ( ) − Storing an element on the queue.
Deletion/Dequeue ( ) − Removing an element from the queue.
We also need to check the status of the queue
to use it efficiently :
Overflow – To check if queue is full.
Underflow – To check if queue is empty.
Queue Data Structure
ALGORITHM OF INSERTION OPERATION
Step 1 − Start
Step 2 – Check if the queue is full.
Step 3 − If the queue is full, display Overflow.
Step 4 − If the queue is not full, increment rear pointer to point to the
next empty space.
Step 5 − Add data element to the queue location, where the rear is
pointing.
Step 6 − End
IMPLEMENTATION OF INSERTION OPERATION
0 1 2 3
0 1 2 3
0 1 2 3
0 1 2 3 0 1 2 3
rea
r
rea
r
rea
r
rea
r
rear= -
1
CODE FOR INSERTION OPERATION
void insert(int data)
{
if (rear < arr.length - 1)
{
arr[++rear] = data;
System.out.println("Element " + data +" is inserted to
Queue !");
}
else
System.out.println("Overflow !");
}
Step 1 − Start
Step 2 – Check if the queue is empty.
Step 3 − If the queue is empty, display Underflow.
Step 4 − If the queue is not empty, access the data where front
is pointing.
Step 5 − Increment front pointer to point to the next available
data element.
Step 6 − End
ALGORITHM OF DELETION OPERATION
0 1 2 3
front=
0
rear=3
IMPLEMENTATION OF DELETION OPERATION
0 1 2 3
0 1 2 3
0 1 2 3 0 1 2 3
fro
nt
fro
nt
fro
nt
front=
4
CODE FOR DELETION OPERATION
void delete()
{
if (rear >= front)
System.out.println("Deleted element=" +arr[front++]);
else
System.out.println("Underflow !");
}

More Related Content

PPTX
STACKS IN DATASTRUCTURE
PPTX
Stack Data Structure
PPTX
Data structure by Digvijay
PPT
Stacks overview with its applications
PPT
PPTX
Stack_Data_Structure.pptx
PPTX
Project of data structure
PPTX
Introduction To Stack
STACKS IN DATASTRUCTURE
Stack Data Structure
Data structure by Digvijay
Stacks overview with its applications
Stack_Data_Structure.pptx
Project of data structure
Introduction To Stack

What's hot (20)

PPTX
Stack_Application_Infix_Prefix.pptx
PPTX
Stacks in Data Structure
PPT
PPTX
Introduction to stack
PPTX
Stack project
PPTX
Stacks in DATA STRUCTURE
PPSX
PDF
STACK ( LIFO STRUCTURE) - Data Structure
PPT
Stack a Data Structure
PPTX
Stack - Data Structure
PPT
Stack Data Structure & It's Application
PPTX
Data structure Stack
PPTX
Stack of Data structure
PPT
stack and queue array implementation in java.
PPT
Stack & queue
PPTX
Stack in Sata Structure
PPT
PPTX
Application of Stack - Yadraj Meena
PPTX
Stacks and Queue - Data Structures
PPTX
Stack Data Structure
Stack_Application_Infix_Prefix.pptx
Stacks in Data Structure
Introduction to stack
Stack project
Stacks in DATA STRUCTURE
STACK ( LIFO STRUCTURE) - Data Structure
Stack a Data Structure
Stack - Data Structure
Stack Data Structure & It's Application
Data structure Stack
Stack of Data structure
stack and queue array implementation in java.
Stack & queue
Stack in Sata Structure
Application of Stack - Yadraj Meena
Stacks and Queue - Data Structures
Stack Data Structure
Ad

Similar to Queue Data Structure (20)

PPTX
Queue and its operations
PPT
PDF
PPTX
VCE Unit 03vv.pptx
PPTX
Basic Queue Operation in DataStructure.pptx
PPTX
Queues in C++
PPTX
queue.pptx
PPTX
Stack and queue
PPT
Lecture three of datat structures ,.The Queue-ds.ppt
PPTX
Stack and Queue.pptx
PPTX
Queues
PPTX
stack & queue
PPT
Stack and queue
PDF
Lab 07 (2).pdfbdvdyve dhdysbsnjsnsvdvydbdns
PPT
Data Structures by Maneesh Boddu
PPT
stack and queue array implementation, java.
PPTX
Queue Data Structure
PDF
PPT
Queues in C++ detailed explanation and examples .ppt
PPTX
Queue data structures and operation on data structures
Queue and its operations
VCE Unit 03vv.pptx
Basic Queue Operation in DataStructure.pptx
Queues in C++
queue.pptx
Stack and queue
Lecture three of datat structures ,.The Queue-ds.ppt
Stack and Queue.pptx
Queues
stack & queue
Stack and queue
Lab 07 (2).pdfbdvdyve dhdysbsnjsnsvdvydbdns
Data Structures by Maneesh Boddu
stack and queue array implementation, java.
Queue Data Structure
Queues in C++ detailed explanation and examples .ppt
Queue data structures and operation on data structures
Ad

Recently uploaded (20)

PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
01-Introduction-to-Information-Management.pdf
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Classroom Observation Tools for Teachers
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
Cell Types and Its function , kingdom of life
PDF
O7-L3 Supply Chain Operations - ICLT Program
PPTX
Institutional Correction lecture only . . .
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
01-Introduction-to-Information-Management.pdf
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
102 student loan defaulters named and shamed – Is someone you know on the list?
O5-L3 Freight Transport Ops (International) V1.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Classroom Observation Tools for Teachers
Week 4 Term 3 Study Techniques revisited.pptx
Cell Types and Its function , kingdom of life
O7-L3 Supply Chain Operations - ICLT Program
Institutional Correction lecture only . . .
VCE English Exam - Section C Student Revision Booklet
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf

Queue Data Structure

  • 2. A queue is open at both its ends. One end is always used to insert data (enqueue) and the other is used to remove data (dequeue).  Queue follows First In First Out (FIFO) methodology, i.e., the data item stored first will be accessed first. It has two pointers – front and rear. Front is used for deletion and rear is used for insertion. The difference between stack and queue is in removing the elements. In a stack we remove the item that has been recently added but in a queue, we remove the item that has been added at the first.
  • 4. OPERATIONS OF QUEUE Insertion/Enqueue ( ) − Storing an element on the queue. Deletion/Dequeue ( ) − Removing an element from the queue. We also need to check the status of the queue to use it efficiently : Overflow – To check if queue is full. Underflow – To check if queue is empty.
  • 6. ALGORITHM OF INSERTION OPERATION Step 1 − Start Step 2 – Check if the queue is full. Step 3 − If the queue is full, display Overflow. Step 4 − If the queue is not full, increment rear pointer to point to the next empty space. Step 5 − Add data element to the queue location, where the rear is pointing. Step 6 − End
  • 7. IMPLEMENTATION OF INSERTION OPERATION 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 rea r rea r rea r rea r rear= - 1
  • 8. CODE FOR INSERTION OPERATION void insert(int data) { if (rear < arr.length - 1) { arr[++rear] = data; System.out.println("Element " + data +" is inserted to Queue !"); } else System.out.println("Overflow !"); }
  • 9. Step 1 − Start Step 2 – Check if the queue is empty. Step 3 − If the queue is empty, display Underflow. Step 4 − If the queue is not empty, access the data where front is pointing. Step 5 − Increment front pointer to point to the next available data element. Step 6 − End ALGORITHM OF DELETION OPERATION
  • 10. 0 1 2 3 front= 0 rear=3 IMPLEMENTATION OF DELETION OPERATION 0 1 2 3 0 1 2 3 0 1 2 3 0 1 2 3 fro nt fro nt fro nt front= 4
  • 11. CODE FOR DELETION OPERATION void delete() { if (rear >= front) System.out.println("Deleted element=" +arr[front++]); else System.out.println("Underflow !"); }