SlideShare a Scribd company logo
1 of 23
QUEUES
Unit 4
Intro
Ashim Lamichhane 2
Movie Hall Ticketing
One Way Traffic
Intro
• Queue is a linear list of elements in which deletion of an element can
take place at one end, called the front and insertion can take place at
the other end, called the rear.
• The first element in a queue will be the first one to be removed from
the list.
• Queues are also called FIFO (First In First Out) i.e. the data item
stored first will be accessed first
Ashim Lamichhane 3
Queue Representation
• In queue, we access both ends for different reasons
Ashim Lamichhane 4
Applications of queue
• Serving requests on a single shared resource, like a printer, CPU task
scheduling etc.
• In real life, Call Center phone systems will use Queues, to hold people
calling them in an order, until a service representative is free.
• Handling of interrupts in real-time systems. The interrupts are
handled in the same order as they arrive, First come first served.
Ashim Lamichhane 5
The queue as an ADT
• A queue q of type T is a finite sequence of elements with the
operations
• MakeEmpty(q): To make q as an empty queue
• IsEmpty(q): To check whether the queue q is empty. Return true if q is empty,
return false otherwise.
• IsFull(q): To check whether the queue q is full. Return true in q is full, return
false otherwise.
• Enqueue(q, x): To insert an item x at the rear of the queue, if and only if q
is not full.
• Dequeue(q): To delete an item from the front of the queue q if and only if q
is not empty.
• Traverse (q): To read entire queue that is display the content of the queue.
Ashim Lamichhane 6
Enqueue Operation
• Queue maintains two data pointers, front and rear
• The following steps should be taken to enqueue(insert) data into
queue –
• Step 1 – Check if queue is full
• Step 2 – if queue is full
produce overflow error and exit
else
increment rear pointer to point next empty space
and add data element to the queue location, where rear is
pointing
• Step 3 - return success
Ashim Lamichhane 7
Ashim Lamichhane 8
Implementation of enqueue()
int enqueue(int data) {
if(isfull())
return 0;
rear = rear + 1;
queue[rear] = data;
return 1;
}
Ashim Lamichhane 9
Dequeue Operation
• Accessing data from queue is a process of two steps
• Access the data from where front is pointing
• And remove the data after access
• The following steps are taken to perform dequeue operation
• Step 1 – Check if queue is empty
• Step 2 – if queue is empty
produce underflow error and exit
else
access data where front is pointing, increment front pointer
to point next available data element
• Step 3 – return success.
Ashim Lamichhane 10
Ashim Lamichhane 11
Implementation of dequeue()
int dequeue() {
if(isempty()) {
return 0;
}
int data = queue[front];
front = front + 1;
return data;
}
Ashim Lamichhane 12
Implementation of queue
• There are two techniques for implementing the queue:
• Array implementation of queue (static memory allocation)
• Linear array implementation (Linear Queue)
• Circular array Implementation (Circular queue)
• Linked list implementation of queue (dynamic memory allocation)
Ashim Lamichhane 13
Array implementation of queue
• The easies way of implementing a queue is by using an Array.
• Initially head(FRONT) and the tail(REAR) of the queue points at the first
index of the array.
• As we add elements to the queue, we can either move tail before
adding another item or we can move the tail after adding the item,
while the head remains at the first index.
Ashim Lamichhane 14
Linear Queue
Ashim Lamichhane 15
Linear Queue
Insertion of an item in queue Deletion of an item from queue
1. Initialize front=0 and rear=-1
if rear>=MAXSIZE-1
print “queue overflow” and return
else
set rear=rear+1
queue[rear]=item
2. end
1. if rear<front
print “queue is empty” and return
else
item=queue[front++]
2. end
Ashim Lamichhane 16
Problems with Linear queue implementation
• Both rear and front indices are increased but never decreased.
• As items are removed from the queue, the storage space at the
beginning of the array is discarded and never used again.
• Wastage of the space is the main problem with linear queue which is
illustrated by the following example.
Ashim Lamichhane 17
Circular queue
• A queue where the start and end of the queue are joined together.
• A circular queue is one in which the insertion of a new element is done
at very first location of the queue if the last location of the queue is
full.
Ashim Lamichhane 18
Ashim Lamichhane 19
Circular queue
isFull() IsEmpty
- If HEAD == (Tail % MAX) + 1
Then Full <- True;
Else Full <- False;
- If they have caught up to each other, then it’s full
- If Head ==Tail
Then Full <- True;
Else Full <- False;
Ashim Lamichhane 20
Circular queue
Enqueue operation Dequeue operation
Step 1. start
Step 2. if (front == (rear+1)%max)
Print error “circular queue overflow “
Step 3. else{
rear = (rear+1)%max
Q[rear] = element;
}
Step 4. stop
Step 1. start
Step 2. if isEmpty() == True
Print error “Queue is Empty“
Step 3. else{
element = Q[front]
front = (front + 1) % max
}
Step 4. stop
Ashim Lamichhane 21
Assignments
• https://github.com/ashim888/dataStructureAndAlgorithm/tree/maste
r/Assignments/assignment_5
Ashim Lamichhane 22
References
• https://www.cs.cmu.edu/~adamchik/15-
121/lectures/Stacks%20and%20Queues/Stacks%20and%20Queues.html
• http://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm
• http://www.studytonight.com/data-structures/queue-data-structure
• https://www.youtube.com/watch?v=g9su-lnW2Ks
• https://www.youtube.com/watch?v=ia__kyuwGag
• https://www.quora.com/What-is-a-circular-queue
• http://basicdatastructures.blogspot.com/2007/12/circular-queue-data-structure.html
• http://btechsmartclass.com/DS/U2_T10.html
• http://scanftree.com/Data_Structure/circular-queue
• http://btechsmartclass.com/DS/U2_T10.html
Ashim Lamichhane 23

More Related Content

What's hot

My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 
Stack data structure
Stack data structureStack data structure
Stack data structure
Tech_MX
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 

What's hot (20)

stack & queue
stack & queuestack & queue
stack & 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)
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Stack a Data Structure
Stack a Data StructureStack a Data Structure
Stack a Data Structure
 
Stack - Data Structure
Stack - Data StructureStack - Data Structure
Stack - Data Structure
 
Stacks
StacksStacks
Stacks
 
stack presentation
stack presentationstack presentation
stack presentation
 
Data structure by Digvijay
Data structure by DigvijayData structure by Digvijay
Data structure by Digvijay
 
Stack data structure
Stack data structureStack data structure
Stack data structure
 
Unit II - LINEAR DATA STRUCTURES
Unit II -  LINEAR DATA STRUCTURESUnit II -  LINEAR DATA STRUCTURES
Unit II - LINEAR DATA STRUCTURES
 
heap Sort Algorithm
heap  Sort Algorithmheap  Sort Algorithm
heap Sort Algorithm
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
single linked list
single linked listsingle linked list
single linked list
 
Linked list
Linked listLinked list
Linked list
 
Stack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADTStack and its Applications : Data Structures ADT
Stack and its Applications : Data Structures ADT
 
Stacks in Data Structure
Stacks in Data StructureStacks in Data Structure
Stacks in Data Structure
 

Viewers also liked

Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
greatqadirgee4u
 
Friedman two way analysis of variance by
Friedman two way analysis of  variance byFriedman two way analysis of  variance by
Friedman two way analysis of variance by
Iybaro Reyes
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
ghhgj jhgh
 
Lecture 10 data structures and algorithms
Lecture 10 data structures and algorithmsLecture 10 data structures and algorithms
Lecture 10 data structures and algorithms
Aakash deep Singhal
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
Abbott
 

Viewers also liked (20)

Searching
SearchingSearching
Searching
 
Linked List
Linked ListLinked List
Linked List
 
Sorting
SortingSorting
Sorting
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Introduction to data_structure
Introduction to data_structureIntroduction to data_structure
Introduction to data_structure
 
Unit 11. Graphics
Unit 11. GraphicsUnit 11. Graphics
Unit 11. Graphics
 
Algorithm big o
Algorithm big oAlgorithm big o
Algorithm big o
 
Algorithm Introduction
Algorithm IntroductionAlgorithm Introduction
Algorithm Introduction
 
Unit 9. Structure and Unions
Unit 9. Structure and UnionsUnit 9. Structure and Unions
Unit 9. Structure and Unions
 
Stacks in algorithems & data structure
Stacks in algorithems & data structureStacks in algorithems & data structure
Stacks in algorithems & data structure
 
Stacks Implementation and Examples
Stacks Implementation and ExamplesStacks Implementation and Examples
Stacks Implementation and Examples
 
Friedman two way analysis of variance by
Friedman two way analysis of  variance byFriedman two way analysis of  variance by
Friedman two way analysis of variance by
 
Tree in data structure
Tree in data structureTree in data structure
Tree in data structure
 
Tree and binary tree
Tree and binary treeTree and binary tree
Tree and binary tree
 
Polish nootation
Polish nootationPolish nootation
Polish nootation
 
Lecture 10 data structures and algorithms
Lecture 10 data structures and algorithmsLecture 10 data structures and algorithms
Lecture 10 data structures and algorithms
 
Stacks and queues
Stacks and queuesStacks and queues
Stacks and queues
 
Unit 8. Pointers
Unit 8. PointersUnit 8. Pointers
Unit 8. Pointers
 
Dsa circular queue
Dsa circular queueDsa circular queue
Dsa circular queue
 
Unit 6. Arrays
Unit 6. ArraysUnit 6. Arrays
Unit 6. Arrays
 

Similar to Queues

queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
MeghaKulkarni27
 

Similar to Queues (20)

Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
Unit – iv queue
Unit – iv    queueUnit – iv    queue
Unit – iv queue
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
Queue
QueueQueue
Queue
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
stacks and queues for public
stacks and queues for publicstacks and queues for public
stacks and queues for public
 
Stack and Queue.pptx
Stack and Queue.pptxStack and Queue.pptx
Stack and Queue.pptx
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
 
Data Structure Lecture 4
Data Structure Lecture 4Data Structure Lecture 4
Data Structure Lecture 4
 
Queues
QueuesQueues
Queues
 
6 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart36 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart3
 
Unit ii linear data structures
Unit ii linear data structures Unit ii linear data structures
Unit ii linear data structures
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]Data Structures - Lecture 6 [queues]
Data Structures - Lecture 6 [queues]
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
10994103.ppt
10994103.ppt10994103.ppt
10994103.ppt
 
Unit 3 stack
Unit   3 stackUnit   3 stack
Unit 3 stack
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 

More from Ashim Lamichhane

More from Ashim Lamichhane (8)

Tree - Data Structure
Tree - Data StructureTree - Data Structure
Tree - Data Structure
 
UNIT 10. Files and file handling in C
UNIT 10. Files and file handling in CUNIT 10. Files and file handling in C
UNIT 10. Files and file handling in C
 
Unit 7. Functions
Unit 7. FunctionsUnit 7. Functions
Unit 7. Functions
 
Unit 5. Control Statement
Unit 5. Control StatementUnit 5. Control Statement
Unit 5. Control Statement
 
Unit 4. Operators and Expression
Unit 4. Operators and Expression  Unit 4. Operators and Expression
Unit 4. Operators and Expression
 
Unit 3. Input and Output
Unit 3. Input and OutputUnit 3. Input and Output
Unit 3. Input and Output
 
Unit 2. Elements of C
Unit 2. Elements of CUnit 2. Elements of C
Unit 2. Elements of C
 
Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer   Unit 1. Problem Solving with Computer
Unit 1. Problem Solving with Computer
 

Recently uploaded

Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
AnaAcapella
 

Recently uploaded (20)

Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in  Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in Uttam Nagar (delhi) call me [🔝9953056974🔝] escort service 24X7
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17How to Add a Tool Tip to a Field in Odoo 17
How to Add a Tool Tip to a Field in Odoo 17
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
How to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptxHow to setup Pycharm environment for Odoo 17.pptx
How to setup Pycharm environment for Odoo 17.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPSSpellings Wk 4 and Wk 5 for Grade 4 at CAPS
Spellings Wk 4 and Wk 5 for Grade 4 at CAPS
 
Basic Intentional Injuries Health Education
Basic Intentional Injuries Health EducationBasic Intentional Injuries Health Education
Basic Intentional Injuries Health Education
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 

Queues

  • 2. Intro Ashim Lamichhane 2 Movie Hall Ticketing One Way Traffic
  • 3. Intro • Queue is a linear list of elements in which deletion of an element can take place at one end, called the front and insertion can take place at the other end, called the rear. • The first element in a queue will be the first one to be removed from the list. • Queues are also called FIFO (First In First Out) i.e. the data item stored first will be accessed first Ashim Lamichhane 3
  • 4. Queue Representation • In queue, we access both ends for different reasons Ashim Lamichhane 4
  • 5. Applications of queue • Serving requests on a single shared resource, like a printer, CPU task scheduling etc. • In real life, Call Center phone systems will use Queues, to hold people calling them in an order, until a service representative is free. • Handling of interrupts in real-time systems. The interrupts are handled in the same order as they arrive, First come first served. Ashim Lamichhane 5
  • 6. The queue as an ADT • A queue q of type T is a finite sequence of elements with the operations • MakeEmpty(q): To make q as an empty queue • IsEmpty(q): To check whether the queue q is empty. Return true if q is empty, return false otherwise. • IsFull(q): To check whether the queue q is full. Return true in q is full, return false otherwise. • Enqueue(q, x): To insert an item x at the rear of the queue, if and only if q is not full. • Dequeue(q): To delete an item from the front of the queue q if and only if q is not empty. • Traverse (q): To read entire queue that is display the content of the queue. Ashim Lamichhane 6
  • 7. Enqueue Operation • Queue maintains two data pointers, front and rear • The following steps should be taken to enqueue(insert) data into queue – • Step 1 – Check if queue is full • Step 2 – if queue is full produce overflow error and exit else increment rear pointer to point next empty space and add data element to the queue location, where rear is pointing • Step 3 - return success Ashim Lamichhane 7
  • 9. Implementation of enqueue() int enqueue(int data) { if(isfull()) return 0; rear = rear + 1; queue[rear] = data; return 1; } Ashim Lamichhane 9
  • 10. Dequeue Operation • Accessing data from queue is a process of two steps • Access the data from where front is pointing • And remove the data after access • The following steps are taken to perform dequeue operation • Step 1 – Check if queue is empty • Step 2 – if queue is empty produce underflow error and exit else access data where front is pointing, increment front pointer to point next available data element • Step 3 – return success. Ashim Lamichhane 10
  • 12. Implementation of dequeue() int dequeue() { if(isempty()) { return 0; } int data = queue[front]; front = front + 1; return data; } Ashim Lamichhane 12
  • 13. Implementation of queue • There are two techniques for implementing the queue: • Array implementation of queue (static memory allocation) • Linear array implementation (Linear Queue) • Circular array Implementation (Circular queue) • Linked list implementation of queue (dynamic memory allocation) Ashim Lamichhane 13
  • 14. Array implementation of queue • The easies way of implementing a queue is by using an Array. • Initially head(FRONT) and the tail(REAR) of the queue points at the first index of the array. • As we add elements to the queue, we can either move tail before adding another item or we can move the tail after adding the item, while the head remains at the first index. Ashim Lamichhane 14
  • 16. Linear Queue Insertion of an item in queue Deletion of an item from queue 1. Initialize front=0 and rear=-1 if rear>=MAXSIZE-1 print “queue overflow” and return else set rear=rear+1 queue[rear]=item 2. end 1. if rear<front print “queue is empty” and return else item=queue[front++] 2. end Ashim Lamichhane 16
  • 17. Problems with Linear queue implementation • Both rear and front indices are increased but never decreased. • As items are removed from the queue, the storage space at the beginning of the array is discarded and never used again. • Wastage of the space is the main problem with linear queue which is illustrated by the following example. Ashim Lamichhane 17
  • 18. Circular queue • A queue where the start and end of the queue are joined together. • A circular queue is one in which the insertion of a new element is done at very first location of the queue if the last location of the queue is full. Ashim Lamichhane 18
  • 20. Circular queue isFull() IsEmpty - If HEAD == (Tail % MAX) + 1 Then Full <- True; Else Full <- False; - If they have caught up to each other, then it’s full - If Head ==Tail Then Full <- True; Else Full <- False; Ashim Lamichhane 20
  • 21. Circular queue Enqueue operation Dequeue operation Step 1. start Step 2. if (front == (rear+1)%max) Print error “circular queue overflow “ Step 3. else{ rear = (rear+1)%max Q[rear] = element; } Step 4. stop Step 1. start Step 2. if isEmpty() == True Print error “Queue is Empty“ Step 3. else{ element = Q[front] front = (front + 1) % max } Step 4. stop Ashim Lamichhane 21
  • 23. References • https://www.cs.cmu.edu/~adamchik/15- 121/lectures/Stacks%20and%20Queues/Stacks%20and%20Queues.html • http://www.tutorialspoint.com/data_structures_algorithms/dsa_queue.htm • http://www.studytonight.com/data-structures/queue-data-structure • https://www.youtube.com/watch?v=g9su-lnW2Ks • https://www.youtube.com/watch?v=ia__kyuwGag • https://www.quora.com/What-is-a-circular-queue • http://basicdatastructures.blogspot.com/2007/12/circular-queue-data-structure.html • http://btechsmartclass.com/DS/U2_T10.html • http://scanftree.com/Data_Structure/circular-queue • http://btechsmartclass.com/DS/U2_T10.html Ashim Lamichhane 23