SlideShare a Scribd company logo
1 of 33
QUEUE
Terminology : Front, Rear
Operations: Insertion(),Deletion(),Display()
Content
• What is Queue?
• Example of Queue.
• Queue working principle
• Queue Operations
• Representation of Queue
• Coding
• output
What is a Queue?
• Queue is a linear data structure in which the
insertion and deletion operations are
performed at two different ends.
• In a queue data structure, adding and
removing elements are performed at two
different positions.
• The insertion is performed at one end and
deletion is performed at another end.
• In a queue data structure, the insertion
operation is performed at a position which is
known as 'rear'
and
• the deletion operation is performed at a
position which is known as 'front'.
QUEUE
QUEUE
Principle
• In queue data structure, the insertion and
deletion operations are performed based on
FIFO (First In First Out) principle.
Operations on a Queue
• enQueue(value) - (To insert an element into
the queue)
• deQueue() - (To delete an element from the
queue)
• display() - (To display the elements of the
queue)
Queue data structure can be
implemented in two ways.
1. Using Array
2. Using Linked List
Queue data structure can be
implemented in two ways.
1. Using Array
Queue data structure can be
implemented in two ways.
2.Using Linked List
Queue Datastructure Using Array
• A queue data structure can be implemented
using one dimensional array.
• The queue implemented using array stores
only fixed number of data values.
Queue Datastructure Using Array
• Just define a one dimensional array of specific size and
insert or delete the values into that array by using FIFO
(First In First Out) principle with the help of
variables 'front' and 'rear'.
• Initially both 'front' and 'rear' are set to -1. Whenever, we
want to insert a new value into the queue, increment 'rear'
value by one and then insert at that position.
• Whenever we want to delete a value from the queue, then
delete the element which is at 'front' position and
increment 'front' value by one.
enQueue Operation
enQueue(value) - Inserting value into
the queue
• enQueue() is a function used to insert a new
element into the queue.
• In a queue, the new element is always
inserted at rear position.
• The enQueue() function takes one integer
value as a parameter and inserts that value
into the queue.
enQueue(value) - Inserting value into
the queue
Step 1 - Check whether queue is FULL.
(rear == SIZE-1)
Step 2 - If it is FULL, then display "Queue is
FULL!!! Insertion is not possible!!!" and
terminate the function.
• Step 3 - If it is NOT FULL, then
increment rear value by one (rear++) and
set queue[rear] = value.
enQueue(value) - Inserting value into
the queue
0 1 2 3 4
Front=-1
10 20 40
30 50
EnQueue(10) EnQueue(20) EnQueue(30) EnQueue(40) EnQueue(50)
Front
Rear Rear Rear Rear Rear
Queue
Rear=-1
DeQueue Operation
deQueue() - (To delete an element
from the queue)
• In a queue data structure, deQueue() is a
function used to delete an element from the
queue.
• In a queue, the element is always deleted
from front position.
• The deQueue() function does not take any
value as parameter.
deQueue() - (To delete an element
from the queue)
Step 1 - Check whether queue is EMPTY.
(front ==-1 && rear==-1)
Step 2 - If it is EMPTY, then display
"Queue is EMPTY!!! Deletion is not
possible!!!" and terminate the function.
Step 3 - If it is NOT EMPTY,
• Then display queue[front] as deleted element.
• Then check whether both front and rear are
equal (front == rear), if it TRUE, then set
both front and rear to '-1' (front = rear = -1).
• Then increment the front value by one
(front ++).
deQueue() - (To delete an element
from the queue)
0 1 2 3 4
10 20 40
30 50
deQueue(10) deQueue(20) deQueue(30) deQueue(40) deQueue(50)
Front Rear
Queue
Front Front Front
Front
Front=Rear=-1
if(front ==-1 && rear==-1)
Queue is Empty, deletion not possible.
Display Operation
display() - (To display the elements of
the queue)
Step 1 - Check whether queue is EMPTY.
(front ==-1 && rear==-1)
Step 2 - If it is EMPTY, then display
"Queue is EMPTY!!!" and terminate the
function.
display() - (To display the elements of
the queue)
Step 3 - If it is NOT EMPTY, then define an
integer variable 'i' and set 'i = front'.
Step 4 - Display 'queue[i]' value and increment
'i' value by one (i++). Repeat the same until 'i'
value reaches to rear (i <= rear)
Coding for Queue
OUTPUT
Thank You

More Related Content

Similar to Queue Data Structure: Implementation and Operations

Similar to Queue Data Structure: Implementation and Operations (20)

queue.pptx
queue.pptxqueue.pptx
queue.pptx
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)Queue AS an ADT (Abstract Data Type)
Queue AS an ADT (Abstract Data Type)
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
Queue data structures and operation on data structures
Queue data structures and operation on data structuresQueue data structures and operation on data structures
Queue data structures and operation on data structures
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
2.1 Queue.pptx
2.1 Queue.pptx2.1 Queue.pptx
2.1 Queue.pptx
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Stack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparationStack and Queue.pptx university exam preparation
Stack and Queue.pptx university exam preparation
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Queue - Operations and Implementations
Queue - Operations and ImplementationsQueue - Operations and Implementations
Queue - Operations and Implementations
 
Queue
QueueQueue
Queue
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS2.1 STACK & QUEUE ADTS
2.1 STACK & QUEUE ADTS
 

More from MattFlordeliza1

bootstrap 4 used for discussion in chcci.pptx
bootstrap 4 used for discussion in chcci.pptxbootstrap 4 used for discussion in chcci.pptx
bootstrap 4 used for discussion in chcci.pptxMattFlordeliza1
 
JDBC OVERVIEW uses from the subject of EDP.pptx
JDBC OVERVIEW uses from the subject of EDP.pptxJDBC OVERVIEW uses from the subject of EDP.pptx
JDBC OVERVIEW uses from the subject of EDP.pptxMattFlordeliza1
 
ACtionlistener in java use in discussion.pptx
ACtionlistener in java use in discussion.pptxACtionlistener in java use in discussion.pptx
ACtionlistener in java use in discussion.pptxMattFlordeliza1
 
PLF-Lesson tsu lecture time 2 units-2.pptx
PLF-Lesson tsu lecture time 2 units-2.pptxPLF-Lesson tsu lecture time 2 units-2.pptx
PLF-Lesson tsu lecture time 2 units-2.pptxMattFlordeliza1
 
PLF-Lesson-5 programming in TSU lec.pptx
PLF-Lesson-5 programming in TSU lec.pptxPLF-Lesson-5 programming in TSU lec.pptx
PLF-Lesson-5 programming in TSU lec.pptxMattFlordeliza1
 
Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxMattFlordeliza1
 

More from MattFlordeliza1 (7)

bootstrap 4 used for discussion in chcci.pptx
bootstrap 4 used for discussion in chcci.pptxbootstrap 4 used for discussion in chcci.pptx
bootstrap 4 used for discussion in chcci.pptx
 
JDBC OVERVIEW uses from the subject of EDP.pptx
JDBC OVERVIEW uses from the subject of EDP.pptxJDBC OVERVIEW uses from the subject of EDP.pptx
JDBC OVERVIEW uses from the subject of EDP.pptx
 
ACtionlistener in java use in discussion.pptx
ACtionlistener in java use in discussion.pptxACtionlistener in java use in discussion.pptx
ACtionlistener in java use in discussion.pptx
 
PLF-Lesson tsu lecture time 2 units-2.pptx
PLF-Lesson tsu lecture time 2 units-2.pptxPLF-Lesson tsu lecture time 2 units-2.pptx
PLF-Lesson tsu lecture time 2 units-2.pptx
 
PLF-Lesson-5 programming in TSU lec.pptx
PLF-Lesson-5 programming in TSU lec.pptxPLF-Lesson-5 programming in TSU lec.pptx
PLF-Lesson-5 programming in TSU lec.pptx
 
Psuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptxPsuedocode1, algorithm1, Flowchart1.pptx
Psuedocode1, algorithm1, Flowchart1.pptx
 
www module 1.pptx
www module 1.pptxwww module 1.pptx
www module 1.pptx
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Neo4j
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Enterprise Knowledge
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024Build your next Gen AI Breakthrough - April 2024
Build your next Gen AI Breakthrough - April 2024
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024Designing IA for AI - Information Architecture Conference 2024
Designing IA for AI - Information Architecture Conference 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 

Queue Data Structure: Implementation and Operations

  • 1. QUEUE Terminology : Front, Rear Operations: Insertion(),Deletion(),Display()
  • 2.
  • 3. Content • What is Queue? • Example of Queue. • Queue working principle • Queue Operations • Representation of Queue • Coding • output
  • 4. What is a Queue? • Queue is a linear data structure in which the insertion and deletion operations are performed at two different ends. • In a queue data structure, adding and removing elements are performed at two different positions. • The insertion is performed at one end and deletion is performed at another end.
  • 5. • In a queue data structure, the insertion operation is performed at a position which is known as 'rear' and • the deletion operation is performed at a position which is known as 'front'.
  • 8. Principle • In queue data structure, the insertion and deletion operations are performed based on FIFO (First In First Out) principle.
  • 9. Operations on a Queue • enQueue(value) - (To insert an element into the queue) • deQueue() - (To delete an element from the queue) • display() - (To display the elements of the queue)
  • 10. Queue data structure can be implemented in two ways. 1. Using Array 2. Using Linked List
  • 11. Queue data structure can be implemented in two ways. 1. Using Array
  • 12. Queue data structure can be implemented in two ways. 2.Using Linked List
  • 13. Queue Datastructure Using Array • A queue data structure can be implemented using one dimensional array. • The queue implemented using array stores only fixed number of data values.
  • 14. Queue Datastructure Using Array • Just define a one dimensional array of specific size and insert or delete the values into that array by using FIFO (First In First Out) principle with the help of variables 'front' and 'rear'. • Initially both 'front' and 'rear' are set to -1. Whenever, we want to insert a new value into the queue, increment 'rear' value by one and then insert at that position. • Whenever we want to delete a value from the queue, then delete the element which is at 'front' position and increment 'front' value by one.
  • 16. enQueue(value) - Inserting value into the queue • enQueue() is a function used to insert a new element into the queue. • In a queue, the new element is always inserted at rear position. • The enQueue() function takes one integer value as a parameter and inserts that value into the queue.
  • 17. enQueue(value) - Inserting value into the queue Step 1 - Check whether queue is FULL. (rear == SIZE-1) Step 2 - If it is FULL, then display "Queue is FULL!!! Insertion is not possible!!!" and terminate the function.
  • 18. • Step 3 - If it is NOT FULL, then increment rear value by one (rear++) and set queue[rear] = value.
  • 19. enQueue(value) - Inserting value into the queue 0 1 2 3 4 Front=-1 10 20 40 30 50 EnQueue(10) EnQueue(20) EnQueue(30) EnQueue(40) EnQueue(50) Front Rear Rear Rear Rear Rear Queue Rear=-1
  • 21. deQueue() - (To delete an element from the queue) • In a queue data structure, deQueue() is a function used to delete an element from the queue. • In a queue, the element is always deleted from front position. • The deQueue() function does not take any value as parameter.
  • 22. deQueue() - (To delete an element from the queue) Step 1 - Check whether queue is EMPTY. (front ==-1 && rear==-1) Step 2 - If it is EMPTY, then display "Queue is EMPTY!!! Deletion is not possible!!!" and terminate the function.
  • 23. Step 3 - If it is NOT EMPTY, • Then display queue[front] as deleted element. • Then check whether both front and rear are equal (front == rear), if it TRUE, then set both front and rear to '-1' (front = rear = -1). • Then increment the front value by one (front ++).
  • 24. deQueue() - (To delete an element from the queue) 0 1 2 3 4 10 20 40 30 50 deQueue(10) deQueue(20) deQueue(30) deQueue(40) deQueue(50) Front Rear Queue Front Front Front Front Front=Rear=-1 if(front ==-1 && rear==-1) Queue is Empty, deletion not possible.
  • 26. display() - (To display the elements of the queue) Step 1 - Check whether queue is EMPTY. (front ==-1 && rear==-1) Step 2 - If it is EMPTY, then display "Queue is EMPTY!!!" and terminate the function.
  • 27. display() - (To display the elements of the queue) Step 3 - If it is NOT EMPTY, then define an integer variable 'i' and set 'i = front'. Step 4 - Display 'queue[i]' value and increment 'i' value by one (i++). Repeat the same until 'i' value reaches to rear (i <= rear)
  • 28.
  • 30.
  • 31.