SlideShare a Scribd company logo
CHAPTER FOUR
part II: Queue
1
Mulugeta G.
Queue
• A data structure that has access to its data at the front and rear
• Operates on FIFO (First In First Out) method
• Has two operations
• Enqueue: inserting data at the rear of the queue
• Dequeue: removing data at the front of the queue
2
front
rear
enqueue
dequeue
A
B
C
Queue
• Example:
• people waiting in line for ticket form a queue.
3
Queue
• Example:
4
Queue
• FIFO Principle of Queue:
– A Queue is like a line waiting to purchase tickets, where
the first person in line is the first person to be served. (i.e.,
First come first serve).
– The first entry that will be removed from the queue, is
called the front of the queue
– The one most recently added, is called the rear
5
Queue
• Basic Operations of Queue
• Enqueue(): Add an element to the end of the queue.
• Dequeue(): Remove an element from the front of the
queue.
• IsEmpty(): Check if the queue is empty.
• IsFull(): Check if the queue is full.
• Peek(): Get the value of the front of the queue without
removing it.
6
Queue
• Basic Operations of Queue
• peek(): Algorithm
•Implementation
7
int peek()
{
return queue[front];
}
begin procedure peek
return queue[front]
end procedure
Queue
• Basic Operations of Queue
•isfull(): Algorithm
Implementation
8
begin procedure isfull
if rear equals to MAXSIZE
return true
else
return false
endif
end procedure
bool isfull()
{
if(rear == MAXSIZE - 1)
return true;
else
return false;
}
Queue
• Basic Operations of Queue
• isempty(): Algorithm
9
begin procedure isempty
if front is less than MIN OR front is greater than rear
return true
else
return false
endif
end procedure
Queue
• Basic Operations of Queue
• isempty(): Implementation
• If the value of front is less than MIN or 0, it tells that the queue
is not yet initialized, hence empty.
10
bool isempty()
{
if(front < 0 || front > rear)
return true;
else
return false;
}
Queue
 Queue operations work as follows:
• Two pointers, FRONT and REAR, are required
• FRONT track the first element of the queue
• REAR track the last element of the queue
• Initially, set value of FRONT and REAR to -1
11
Queue
 enqueue()
• Steps to enqueue (insert) data into a queue:
1. Check if the queue is full or not
2. If the queue is full, produce overflow error and exit.
3. If the queue is not full, increment rear pointer to point the next
empty space.
4. Add data element to the queue location, where the rear is pointing.
5. return success.
12
Queue
 enqueue()
13
Algorithm Implementation
begin procedure enqueue(data)
if queue is full
return overflow
endif
rear ← rear + 1
queue[rear] ← data
return true
end procedure
int enqueue(int data)
{
if(isfull())
return 0;
rear = rear + 1;
queue[rear] = data;
return 1;
}
Queue
 dequeue()
• steps to perform dequeue operation:
1. Check if the queue is empty or not.
2. If the queue is empty, produce underflow error and exit.
3. If the queue is not empty, access the data where front is pointing.
4. Increment front pointer to point to the next available data element.
5. Return success.
14
Queue
 dequeue()
15
Algorithm Implementation
begin procedure dequeue
if queue is empty
return underflow
endif
data = queue[front]
front ← front + 1
return true
end procedure
int dequeue()
{
if(isempty())
return 0;
int data = queue[front];
front = front + 1;
return data;
}
Typesof Queue
16
In Linear Queue, an insertion takes
place from one end while the
deletion occurs from another end.
It is similar to the linear Queue
except that the last element of
the queue is connected to the
first element.
It is a special type of queue
data structure in which every
element has a priority
associated with it.
In Double Ended Queue, insertion and
deletion can be done from both ends of the
queue either from the front or rear.
Queue Implementation
• Two ways of implementing the Queue: Array and Linked list.
Using Array
17
void enqueue(int queue[], int item)
{
if (isfull())
{
cout<<"overflow";
}
else
{
rear = rear + 1;
queue[rear]=item;
}
}
int dequeue (int queue[], int item)
{
if (isempty())
{
cout<<"underflow";
}
else
{
item = queue[front];
front = front + 1;
return item;
}
}
Queue Implementation
• Two ways of implementing the Queue: Array and Linked list.
Using Linked List
18
void enqueue(struct node *ptr, int item) {
ptr = (struct node *) malloc (sizeof(struct
node)); if(ptr == NULL) {
cout<<"nOVERFLOWn";
return; }
else {
ptr -> data = item;
if(front == NULL) {
front = ptr;
rear = ptr;
front -> next = NULL;
rear -> next = NULL; }
else {
rear -> next = ptr;
rear = ptr;
rear->next = NULL; } } }
void dequeue
(struct node *ptr)
{
if(front == NULL)
{
cout<<"nUNDERFLOWn
";
return;
}
else
{
ptr = front;
front = front -> next;
delete ptr;
}
}
Applicationof Queue
i. In operating systems for handling interrupts
ii. To maintain the play list in media players in order to add and
remove the songs from the play-list.
iii. Disk Driver- maintains a queue of disk input/output requests
iv. Task scheduler in multiprocessing system- maintains priority
queues of processes
v. Telephone calls in a busy environment –maintains a queue of
telephone calls
vi. Simulation of waiting line- maintains a queue of persons
19
PART III
Stack
20

More Related Content

Similar to @Chapter 4 DSA Part II.pptx

Queue
QueueQueue
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
MeghaKulkarni27
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
Toseef Hasan
 
Unit-ii-Queue ADT.pptx
Unit-ii-Queue ADT.pptxUnit-ii-Queue ADT.pptx
Unit-ii-Queue ADT.pptx
Mano Arun
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
MuhammadUmerIhtisham
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
RAtna29
 
QUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptxQUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptx
TajBir4
 
Queues
QueuesQueues
Queue
QueueQueue
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
skilljiolms
 
Queues
Queues Queues
Queues
nidhisatija1
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
soniya555961
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
Poulami Das Akuli
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
singhprpg
 
Stack and queue
Stack and queueStack and queue
Stack and queue
LavanyaJ28
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
MattFlordeliza1
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
Prof. Dr. K. Adisesha
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
maneesh boddu
 
Stack and queue
Stack and queueStack and queue
Stack and queue
Anil Kumar Prajapati
 

Similar to @Chapter 4 DSA Part II.pptx (20)

Queue
QueueQueue
Queue
 
Queue
QueueQueue
Queue
 
queueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptxqueueppt-191018053228 (1).pptx
queueppt-191018053228 (1).pptx
 
Queues presentation
Queues presentationQueues presentation
Queues presentation
 
Unit-ii-Queue ADT.pptx
Unit-ii-Queue ADT.pptxUnit-ii-Queue ADT.pptx
Unit-ii-Queue ADT.pptx
 
LEC4-DS ALGO.pdf
LEC4-DS  ALGO.pdfLEC4-DS  ALGO.pdf
LEC4-DS ALGO.pdf
 
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbbqueuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
queuesArrays.ppt bbbbbbbbbbbbbbbbbbbbbbbbbb
 
QUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptxQUEUE PPT BY KULJIT SINGH.pptx
QUEUE PPT BY KULJIT SINGH.pptx
 
Queues
QueuesQueues
Queues
 
Queue
QueueQueue
Queue
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Queues
Queues Queues
Queues
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
 
Data Structures by Maneesh Boddu
Data Structures by Maneesh BodduData Structures by Maneesh Boddu
Data Structures by Maneesh Boddu
 
Stack and queue
Stack and queueStack and queue
Stack and queue
 

Recently uploaded

TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
Tier1 app
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
vrstrong314
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
Philip Schwarz
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
IES VE
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
XfilesPro
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
kalichargn70th171
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
e20449
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
AMB-Review
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
Juraj Vysvader
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
Globus
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
takuyayamamoto1800
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
Tendenci - The Open Source AMS (Association Management Software)
 

Recently uploaded (20)

TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERRORTROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
TROUBLESHOOTING 9 TYPES OF OUTOFMEMORYERROR
 
Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
top nidhi software solution freedownload
top nidhi software solution freedownloadtop nidhi software solution freedownload
top nidhi software solution freedownload
 
A Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of PassageA Sighting of filterA in Typelevel Rite of Passage
A Sighting of filterA in Typelevel Rite of Passage
 
Using IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New ZealandUsing IESVE for Room Loads Analysis - Australia & New Zealand
Using IESVE for Room Loads Analysis - Australia & New Zealand
 
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, BetterWebinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
Webinar: Salesforce Document Management 2.0 - Smarter, Faster, Better
 
A Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdfA Comprehensive Look at Generative AI in Retail App Testing.pdf
A Comprehensive Look at Generative AI in Retail App Testing.pdf
 
Graphic Design Crash Course for beginners
Graphic Design Crash Course for beginnersGraphic Design Crash Course for beginners
Graphic Design Crash Course for beginners
 
Understanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSageUnderstanding Globus Data Transfers with NetSage
Understanding Globus Data Transfers with NetSage
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Vitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume MontevideoVitthal Shirke Microservices Resume Montevideo
Vitthal Shirke Microservices Resume Montevideo
 
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdfDominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
Dominate Social Media with TubeTrivia AI’s Addictive Quiz Videos.pdf
 
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
In 2015, I used to write extensions for Joomla, WordPress, phpBB3, etc and I ...
 
Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024Globus Compute Introduction - GlobusWorld 2024
Globus Compute Introduction - GlobusWorld 2024
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...Developing Distributed High-performance Computing Capabilities of an Open Sci...
Developing Distributed High-performance Computing Capabilities of an Open Sci...
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoamOpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
OpenFOAM solver for Helmholtz equation, helmholtzFoam / helmholtzBubbleFoam
 
Corporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMSCorporate Management | Session 3 of 3 | Tendenci AMS
Corporate Management | Session 3 of 3 | Tendenci AMS
 

@Chapter 4 DSA Part II.pptx

  • 1. CHAPTER FOUR part II: Queue 1 Mulugeta G.
  • 2. Queue • A data structure that has access to its data at the front and rear • Operates on FIFO (First In First Out) method • Has two operations • Enqueue: inserting data at the rear of the queue • Dequeue: removing data at the front of the queue 2 front rear enqueue dequeue A B C
  • 3. Queue • Example: • people waiting in line for ticket form a queue. 3
  • 5. Queue • FIFO Principle of Queue: – A Queue is like a line waiting to purchase tickets, where the first person in line is the first person to be served. (i.e., First come first serve). – The first entry that will be removed from the queue, is called the front of the queue – The one most recently added, is called the rear 5
  • 6. Queue • Basic Operations of Queue • Enqueue(): Add an element to the end of the queue. • Dequeue(): Remove an element from the front of the queue. • IsEmpty(): Check if the queue is empty. • IsFull(): Check if the queue is full. • Peek(): Get the value of the front of the queue without removing it. 6
  • 7. Queue • Basic Operations of Queue • peek(): Algorithm •Implementation 7 int peek() { return queue[front]; } begin procedure peek return queue[front] end procedure
  • 8. Queue • Basic Operations of Queue •isfull(): Algorithm Implementation 8 begin procedure isfull if rear equals to MAXSIZE return true else return false endif end procedure bool isfull() { if(rear == MAXSIZE - 1) return true; else return false; }
  • 9. Queue • Basic Operations of Queue • isempty(): Algorithm 9 begin procedure isempty if front is less than MIN OR front is greater than rear return true else return false endif end procedure
  • 10. Queue • Basic Operations of Queue • isempty(): Implementation • If the value of front is less than MIN or 0, it tells that the queue is not yet initialized, hence empty. 10 bool isempty() { if(front < 0 || front > rear) return true; else return false; }
  • 11. Queue  Queue operations work as follows: • Two pointers, FRONT and REAR, are required • FRONT track the first element of the queue • REAR track the last element of the queue • Initially, set value of FRONT and REAR to -1 11
  • 12. Queue  enqueue() • Steps to enqueue (insert) data into a queue: 1. Check if the queue is full or not 2. If the queue is full, produce overflow error and exit. 3. If the queue is not full, increment rear pointer to point the next empty space. 4. Add data element to the queue location, where the rear is pointing. 5. return success. 12
  • 13. Queue  enqueue() 13 Algorithm Implementation begin procedure enqueue(data) if queue is full return overflow endif rear ← rear + 1 queue[rear] ← data return true end procedure int enqueue(int data) { if(isfull()) return 0; rear = rear + 1; queue[rear] = data; return 1; }
  • 14. Queue  dequeue() • steps to perform dequeue operation: 1. Check if the queue is empty or not. 2. If the queue is empty, produce underflow error and exit. 3. If the queue is not empty, access the data where front is pointing. 4. Increment front pointer to point to the next available data element. 5. Return success. 14
  • 15. Queue  dequeue() 15 Algorithm Implementation begin procedure dequeue if queue is empty return underflow endif data = queue[front] front ← front + 1 return true end procedure int dequeue() { if(isempty()) return 0; int data = queue[front]; front = front + 1; return data; }
  • 16. Typesof Queue 16 In Linear Queue, an insertion takes place from one end while the deletion occurs from another end. It is similar to the linear Queue except that the last element of the queue is connected to the first element. It is a special type of queue data structure in which every element has a priority associated with it. In Double Ended Queue, insertion and deletion can be done from both ends of the queue either from the front or rear.
  • 17. Queue Implementation • Two ways of implementing the Queue: Array and Linked list. Using Array 17 void enqueue(int queue[], int item) { if (isfull()) { cout<<"overflow"; } else { rear = rear + 1; queue[rear]=item; } } int dequeue (int queue[], int item) { if (isempty()) { cout<<"underflow"; } else { item = queue[front]; front = front + 1; return item; } }
  • 18. Queue Implementation • Two ways of implementing the Queue: Array and Linked list. Using Linked List 18 void enqueue(struct node *ptr, int item) { ptr = (struct node *) malloc (sizeof(struct node)); if(ptr == NULL) { cout<<"nOVERFLOWn"; return; } else { ptr -> data = item; if(front == NULL) { front = ptr; rear = ptr; front -> next = NULL; rear -> next = NULL; } else { rear -> next = ptr; rear = ptr; rear->next = NULL; } } } void dequeue (struct node *ptr) { if(front == NULL) { cout<<"nUNDERFLOWn "; return; } else { ptr = front; front = front -> next; delete ptr; } }
  • 19. Applicationof Queue i. In operating systems for handling interrupts ii. To maintain the play list in media players in order to add and remove the songs from the play-list. iii. Disk Driver- maintains a queue of disk input/output requests iv. Task scheduler in multiprocessing system- maintains priority queues of processes v. Telephone calls in a busy environment –maintains a queue of telephone calls vi. Simulation of waiting line- maintains a queue of persons 19