SlideShare ist ein Scribd-Unternehmen logo
1 von 15
- By Sonali Soni
Introduction to Queue.
Operations on Queue.
Representation of Queue in memory.
Application of Queue.
Queue is an ordered group of homogeneous
items of elements.
A queue has two ends - front end & rear
end.
Insertion can take place at rear end &
deletion can take place at front end.
Queue is also known as First In First
Out(FIFO) data structure.
Insertion & Deletion operations are known
as Enqueue & Dequeue respectively.
Front Rear
The following operations are performed on
queue:-
1. CreateQueue(q)- To create q as an empty queue.
2. Enqueue(q, i)- To insert an element i in the
queue.
3. Dequeue(q)- To access & remove an element of
the queue.
4. Peek(q)- To access the first element of the
queue without removing it.
5. IsFull(q)- to check whether the queue is full.
6. IsEmpty(q)- To check whether the queue is
empty.
Queue can be represented in memory using linear
array or linear linked list.
A queue represented using a linked list is called a
linked queue.
The overflow condition for array implementation is
front is equal to zero & rear is equal to (size of
array)-1.
The underflow condition for array implementation is
front is equal to -1.
typedef struct nodetype
{
int info;
struct nodetype *next;
}node;
typedef struct
{
node *front;
node *rear;
}queue;
We define two datatypes- node &
queue.
The datatype queue, a structure
whose first element front holds the
address of first element of queue &
second element rear holds the
address of last element of the
queue.
front rear
5 10 20 0
CREATING AN EMPTY QUEUE
void CreateQueue(queue *pq)
{
pq->front=pq->rear=NULL;
}
The front and rear end of the queue are
initialized to NULL.
typedef enum {true,false}boolean;
boolean IsEmpty(queue *pq)
{
if(pq->front==NULL)
return true;
else
return false;
}
void Enqueue(queue *pq, int item)
{
node *ptr;
ptr=(node *)malloc(sizeof(node));
ptr->info=item;
ptr->next=NULL;
if(pq->rear==NULL)
pq->front=pq->rear=ptr;
else
{
(pq->rear)->next=ptr;
pq->rear=ptr;
}
}
int Dequeue(queue *pq)
{
int temp;
node *ptr;
temp=(pq->front)->info;
ptr=pq->front;
if(pq->front==pq->rear)
pq->front=pq->rear=NULL;
else
pq->front=(pq->front)->next;
free(ptr);
return temp;
}
Queue is used to access files from a
disk system.
In a multiprogramming environment,
queue is used for CPU scheduling or
job scheduling of operating system.
In ticket reservation system, queue
can be used for issuing tickets to the
customers.
Queue

Weitere Àhnliche Inhalte

Was ist angesagt?

Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
Jsaddam Hussain
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
eShikshak
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
Senthil Kumar
 

Was ist angesagt? (20)

Deque and its applications
Deque and its applicationsDeque and its applications
Deque and its applications
 
Queues in C++
Queues in C++Queues in C++
Queues in C++
 
Queue in Data Structure
Queue in Data StructureQueue in Data Structure
Queue in Data Structure
 
Queue
QueueQueue
Queue
 
Leniar datastructure
Leniar datastructureLeniar datastructure
Leniar datastructure
 
Queue
QueueQueue
Queue
 
Queue as data_structure
Queue as data_structureQueue as data_structure
Queue as data_structure
 
Queue
QueueQueue
Queue
 
Queue oop
Queue   oopQueue   oop
Queue oop
 
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
 
My lectures circular queue
My lectures circular queueMy lectures circular queue
My lectures circular queue
 
Circular queue
Circular queueCircular queue
Circular queue
 
Queues
QueuesQueues
Queues
 
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 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 Structure (Queue)
Data Structure (Queue)Data Structure (Queue)
Data Structure (Queue)
 
Stacks and Queue - Data Structures
Stacks and Queue - Data StructuresStacks and Queue - Data Structures
Stacks and Queue - Data Structures
 
Queue implementation
Queue implementationQueue implementation
Queue implementation
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 

Ähnlich wie Queue

Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
Victor Palmar
 

Ähnlich wie Queue (20)

@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx@Chapter 4 DSA Part II.pptx
@Chapter 4 DSA Part II.pptx
 
VCE Unit 03vv.pptx
VCE Unit 03vv.pptxVCE Unit 03vv.pptx
VCE Unit 03vv.pptx
 
Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)Queue Data Structure (w/ php egs)
Queue Data Structure (w/ php egs)
 
Lecture 2d queues
Lecture 2d queuesLecture 2d queues
Lecture 2d queues
 
Queues.ppt
Queues.pptQueues.ppt
Queues.ppt
 
Difference between stack and queue
Difference between stack and queueDifference between stack and queue
Difference between stack and queue
 
Unit 4 queue
Unit   4 queueUnit   4 queue
Unit 4 queue
 
Stack and Queue
Stack and Queue Stack and Queue
Stack and Queue
 
Queue and its operations
Queue and its operationsQueue and its operations
Queue and its operations
 
Stack.pptx
Stack.pptxStack.pptx
Stack.pptx
 
Queue
QueueQueue
Queue
 
6 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart36 chapter3 list_stackqueuepart3
6 chapter3 list_stackqueuepart3
 
Queue Data Structure
Queue Data StructureQueue Data Structure
Queue Data Structure
 
Queue(lecture8).pptx
Queue(lecture8).pptxQueue(lecture8).pptx
Queue(lecture8).pptx
 
Data Structure Lecture 4
Data Structure Lecture 4Data Structure Lecture 4
Data Structure Lecture 4
 
QUEUE.pptx
QUEUE.pptxQUEUE.pptx
QUEUE.pptx
 
Data structures
Data structuresData structures
Data structures
 
Queue
QueueQueue
Queue
 
DS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptxDS UNIT2QUEUES.pptx
DS UNIT2QUEUES.pptx
 
Queue - Data Structure - Notes
Queue - Data Structure - NotesQueue - Data Structure - Notes
Queue - Data Structure - Notes
 

KĂŒrzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 

KĂŒrzlich hochgeladen (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Asian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptxAsian American Pacific Islander Month DDSD 2024.pptx
Asian American Pacific Islander Month DDSD 2024.pptx
 
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
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
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.
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 

Queue

  • 1. - By Sonali Soni
  • 2. Introduction to Queue. Operations on Queue. Representation of Queue in memory. Application of Queue.
  • 3. Queue is an ordered group of homogeneous items of elements. A queue has two ends - front end & rear end. Insertion can take place at rear end & deletion can take place at front end.
  • 4. Queue is also known as First In First Out(FIFO) data structure. Insertion & Deletion operations are known as Enqueue & Dequeue respectively. Front Rear
  • 5. The following operations are performed on queue:- 1. CreateQueue(q)- To create q as an empty queue. 2. Enqueue(q, i)- To insert an element i in the queue. 3. Dequeue(q)- To access & remove an element of the queue. 4. Peek(q)- To access the first element of the queue without removing it. 5. IsFull(q)- to check whether the queue is full. 6. IsEmpty(q)- To check whether the queue is empty.
  • 6. Queue can be represented in memory using linear array or linear linked list. A queue represented using a linked list is called a linked queue. The overflow condition for array implementation is front is equal to zero & rear is equal to (size of array)-1. The underflow condition for array implementation is front is equal to -1.
  • 7. typedef struct nodetype { int info; struct nodetype *next; }node; typedef struct { node *front; node *rear; }queue;
  • 8. We define two datatypes- node & queue. The datatype queue, a structure whose first element front holds the address of first element of queue & second element rear holds the address of last element of the queue.
  • 10. CREATING AN EMPTY QUEUE void CreateQueue(queue *pq) { pq->front=pq->rear=NULL; } The front and rear end of the queue are initialized to NULL.
  • 11. typedef enum {true,false}boolean; boolean IsEmpty(queue *pq) { if(pq->front==NULL) return true; else return false; }
  • 12. void Enqueue(queue *pq, int item) { node *ptr; ptr=(node *)malloc(sizeof(node)); ptr->info=item; ptr->next=NULL; if(pq->rear==NULL) pq->front=pq->rear=ptr; else { (pq->rear)->next=ptr; pq->rear=ptr; } }
  • 13. int Dequeue(queue *pq) { int temp; node *ptr; temp=(pq->front)->info; ptr=pq->front; if(pq->front==pq->rear) pq->front=pq->rear=NULL; else pq->front=(pq->front)->next; free(ptr); return temp; }
  • 14. Queue is used to access files from a disk system. In a multiprogramming environment, queue is used for CPU scheduling or job scheduling of operating system. In ticket reservation system, queue can be used for issuing tickets to the customers.