SlideShare a Scribd company logo
1 of 5
Chapter 2 (Part 2)
Queue
2.1 Introduction to Queue
Queue is a data structure in which new items are added from one
end and existing items are removed from another end. It follows
First In First Out (FIFO) principle. The end from which items
are removed is called front of the queue. The end from which
items are added is called rear of the queue.
2.2 Queue Operations
2.2.1 Enqueue
Enqueue is the operation from which an item is inserted to the
queue from the rear end. This operation is not possible in the
fully filled fixed size queue.
2.2.2 Dequeue
Dequeue is the operation from which an item is removed from
the queue from the front end. This operation is not possible in
the empty queue.
2.2.3 Example showing queue operation
2.3 Linear Queue Implementation
Linear queue is a queue in which traversal through the queue is
possible only once. Once the element is deleted from a position,
no other element can be inserted at the same position. A linear
queue is called contiguous if it is implemented using array. A
linear queue is called linked if it is implemented using pointer or
dynamic memory allocation.
2.3.1 Contiguous Linear Queue (Algorithm)
2.3.1.1 Enqueue Operation
1. If (rear == N - 1)
a) display “Queue is full”
2. Else :
a) If (front == rear == -1) :
i) Set front = 0
ii) Set rear = 0
Else :
i) Set rear = rear + 1
b) Queue[rear] = item
3. Exit
2.3.1.1 Dequeue Operation
1. If (front == -1) :
a) display “Queue is empty”
2. Else :
a) item = queue[front]
b) If (front == rear) :
i) Set front = -1
ii) Set rear = -1
Else :
i) Set front = front + 1
3. Exit
2.4 Circular Queue Implementation
Circular queue is a queue in which the last position is connected
to the first position and enables reusing of the position when the
item is dequeued. It is also called ‘Ring Buffer’.
2.4.1 Enqueue Operation (Algorithm)
1. If ( (front == 0 and rear == N-1) or (front == rear + 1) ) :
a) Print “Queue is full”
2. Else :
a) If (front == rear == -1) :
i) Set front = 0
ii) Set rear = 0
Else if (rear = N-1) :
i) Set rear = 0
Else :
i) Set rear = rear + 1
b) Queue[rear] = item
3. Exit
2.4.2 Dequeue Operation (Algorithm)
1. If (front == -1) :
a) display “Queue is empty”
2. Else :
a) item = queue[front]
b) If (front == rear) :
i) Set front = -1
ii) Set rear = -1
Else if (front == N-1) :
i) Set front = 0
Else :
i) Set front = front + 1
3. Exit
2.5 Priority Queue
Priority queue is a queue in which each item is associated with a
priority when enqueued into the queue and an item with highest
priority is dequeued from the queue. The front points to the
highest priority item. This type of queue is the extension of
general queue.

More Related Content

What's hot

What's hot (20)

Sorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - NotesSorting and Searching - Data Structure - Notes
Sorting and Searching - Data Structure - Notes
 
queue & its applications
queue & its applicationsqueue & its applications
queue & its applications
 
Selection sort
Selection sortSelection sort
Selection sort
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Queues-and-CQueue-Implementation
Queues-and-CQueue-ImplementationQueues-and-CQueue-Implementation
Queues-and-CQueue-Implementation
 
Selection sort
Selection sortSelection sort
Selection sort
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Detalied information of queue
Detalied information of queueDetalied information of queue
Detalied information of queue
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority QueueWhat is Stack, Its Operations, Queue, Circular Queue, Priority Queue
What is Stack, Its Operations, Queue, Circular Queue, Priority Queue
 
Quick sort
Quick sortQuick sort
Quick sort
 
QUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING CQUEUE IN DATA STRUCTURE USING C
QUEUE IN DATA STRUCTURE USING C
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Queue
QueueQueue
Queue
 
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)
 
Queue
QueueQueue
Queue
 
Priority queues
Priority queuesPriority queues
Priority queues
 
Queue by rajanikanth
Queue by rajanikanthQueue by rajanikanth
Queue by rajanikanth
 
Data Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Queue
QueueQueue
Queue
 

Similar to Queue - Operations and Implementations

Similar to Queue - Operations and Implementations (20)

Queue
QueueQueue
Queue
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
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
 
Queue
QueueQueue
Queue
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
@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
QueueQueue
Queue
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
2.1 Queue.pptx
2.1 Queue.pptx2.1 Queue.pptx
2.1 Queue.pptx
 
Data Structure Lecture 4
Data Structure Lecture 4Data Structure Lecture 4
Data Structure Lecture 4
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
4. Queues in Data Structure
4. Queues in Data Structure4. Queues in Data Structure
4. Queues in Data Structure
 
Lect 17-18 Zaheer Abbas
Lect 17-18 Zaheer AbbasLect 17-18 Zaheer Abbas
Lect 17-18 Zaheer Abbas
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
Circular queue
Circular queueCircular queue
Circular queue
 

More from Sagacious IT Solution

More from Sagacious IT Solution (16)

List - Operations and Implementation
List - Operations and ImplementationList - Operations and Implementation
List - Operations and Implementation
 
Stack - Operations and Applications
Stack - Operations and ApplicationsStack - Operations and Applications
Stack - Operations and Applications
 
Introduction to Data Structure and Algorithm
Introduction to Data Structure and AlgorithmIntroduction to Data Structure and Algorithm
Introduction to Data Structure and Algorithm
 
Neural Networks
Neural NetworksNeural Networks
Neural Networks
 
Machine Learning Algorithms
Machine Learning AlgorithmsMachine Learning Algorithms
Machine Learning Algorithms
 
Natural Language Processing
Natural Language ProcessingNatural Language Processing
Natural Language Processing
 
Expert System
Expert SystemExpert System
Expert System
 
Game Playing Search Techniques - Examples
Game Playing Search Techniques - ExamplesGame Playing Search Techniques - Examples
Game Playing Search Techniques - Examples
 
Uninformed Search Examples
Uninformed Search ExamplesUninformed Search Examples
Uninformed Search Examples
 
Examples of Informed Search
Examples of Informed SearchExamples of Informed Search
Examples of Informed Search
 
Searching Algorithm
Searching AlgorithmSearching Algorithm
Searching Algorithm
 
Knowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and ReasoningKnowledge Representation, Inference and Reasoning
Knowledge Representation, Inference and Reasoning
 
Structured Knowledge Representation
Structured Knowledge RepresentationStructured Knowledge Representation
Structured Knowledge Representation
 
Problem Solving Techniques
Problem Solving TechniquesProblem Solving Techniques
Problem Solving Techniques
 
Crypto Arithmetic Problem - Example
Crypto Arithmetic Problem - ExampleCrypto Arithmetic Problem - Example
Crypto Arithmetic Problem - Example
 
Introduction To Artificial Intelligence
Introduction To Artificial IntelligenceIntroduction To Artificial Intelligence
Introduction To Artificial Intelligence
 

Recently uploaded

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEroselinkalist12
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage examplePragyanshuParadkar1
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHC Sai Kiran
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture designssuser87fa0c1
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxbritheesh05
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVRajaP95
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxKartikeyaDwivedi3
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .Satyam Kumar
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 

Recently uploaded (20)

INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETEINFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
INFLUENCE OF NANOSILICA ON THE PROPERTIES OF CONCRETE
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
DATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage exampleDATA ANALYTICS PPT definition usage example
DATA ANALYTICS PPT definition usage example
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
Introduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECHIntroduction to Machine Learning Unit-3 for II MECH
Introduction to Machine Learning Unit-3 for II MECH
 
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
VICTOR MAESTRE RAMIREZ - Planetary Defender on NASA's Double Asteroid Redirec...
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
pipeline in computer architecture design
pipeline in computer architecture  designpipeline in computer architecture  design
pipeline in computer architecture design
 
Artificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptxArtificial-Intelligence-in-Electronics (K).pptx
Artificial-Intelligence-in-Electronics (K).pptx
 
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IVHARMONY IN THE NATURE AND EXISTENCE - Unit-IV
HARMONY IN THE NATURE AND EXISTENCE - Unit-IV
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
POWER SYSTEMS-1 Complete notes examples
POWER SYSTEMS-1 Complete notes  examplesPOWER SYSTEMS-1 Complete notes  examples
POWER SYSTEMS-1 Complete notes examples
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Concrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptxConcrete Mix Design - IS 10262-2019 - .pptx
Concrete Mix Design - IS 10262-2019 - .pptx
 
Churning of Butter, Factors affecting .
Churning of Butter, Factors affecting  .Churning of Butter, Factors affecting  .
Churning of Butter, Factors affecting .
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 

Queue - Operations and Implementations

  • 1. Chapter 2 (Part 2) Queue 2.1 Introduction to Queue Queue is a data structure in which new items are added from one end and existing items are removed from another end. It follows First In First Out (FIFO) principle. The end from which items are removed is called front of the queue. The end from which items are added is called rear of the queue. 2.2 Queue Operations 2.2.1 Enqueue Enqueue is the operation from which an item is inserted to the queue from the rear end. This operation is not possible in the fully filled fixed size queue. 2.2.2 Dequeue Dequeue is the operation from which an item is removed from the queue from the front end. This operation is not possible in the empty queue. 2.2.3 Example showing queue operation
  • 2. 2.3 Linear Queue Implementation
  • 3. Linear queue is a queue in which traversal through the queue is possible only once. Once the element is deleted from a position, no other element can be inserted at the same position. A linear queue is called contiguous if it is implemented using array. A linear queue is called linked if it is implemented using pointer or dynamic memory allocation. 2.3.1 Contiguous Linear Queue (Algorithm) 2.3.1.1 Enqueue Operation 1. If (rear == N - 1) a) display “Queue is full” 2. Else : a) If (front == rear == -1) : i) Set front = 0 ii) Set rear = 0 Else : i) Set rear = rear + 1 b) Queue[rear] = item 3. Exit 2.3.1.1 Dequeue Operation 1. If (front == -1) : a) display “Queue is empty”
  • 4. 2. Else : a) item = queue[front] b) If (front == rear) : i) Set front = -1 ii) Set rear = -1 Else : i) Set front = front + 1 3. Exit 2.4 Circular Queue Implementation Circular queue is a queue in which the last position is connected to the first position and enables reusing of the position when the item is dequeued. It is also called ‘Ring Buffer’. 2.4.1 Enqueue Operation (Algorithm) 1. If ( (front == 0 and rear == N-1) or (front == rear + 1) ) : a) Print “Queue is full” 2. Else : a) If (front == rear == -1) :
  • 5. i) Set front = 0 ii) Set rear = 0 Else if (rear = N-1) : i) Set rear = 0 Else : i) Set rear = rear + 1 b) Queue[rear] = item 3. Exit 2.4.2 Dequeue Operation (Algorithm) 1. If (front == -1) : a) display “Queue is empty” 2. Else : a) item = queue[front] b) If (front == rear) : i) Set front = -1 ii) Set rear = -1 Else if (front == N-1) : i) Set front = 0 Else : i) Set front = front + 1 3. Exit 2.5 Priority Queue Priority queue is a queue in which each item is associated with a priority when enqueued into the queue and an item with highest priority is dequeued from the queue. The front points to the highest priority item. This type of queue is the extension of general queue.