SlideShare a Scribd company logo
Implementation of queue using linked
list
Submitted to
Nemi Chandra Rathore
HEAD OF THE DEPARTMENT
Presented by
Balmukund jha
Mehul Mohan
CONTENTS
• What is queue?
• Real world examples of queue.
• Applications of queue.
• Queue implementation.
• Advantage of linked list over array.
• Operations on queue.
• Implementation of queue using singly linked list .
• Create queue implementation using singly linked list.
• Implementation of queue using doubly linked list.
• Create queue implementation using doubly linked list.
• Time complexity .
• Summary.
WHAT IS QUEUE?
• Queue is a linear data structure.
• It is used for temporary storage of data values.
• A new element is added at one end called rear
end .
• The existing elements deleted from the other
end called front end.
• First in first out property.
Real world example of queue
 At bank counter.
 People on an escalator.
 At ATM machine.
 In one-way road.
At bank counter
People on an escalator.
Queue at ATM
At one-way road
Application of queue
• Queues are widely used as waiting lists for a single
shared resource like printer, disk, cpu.
• Queues are used to transfer data asynchronously
between two processes , e.g., file IO, sockets.
• Queue are used as buffers on MP3 players and
portable CD players , iPod playlist.
• Queues are used in playlist for jukebox to add songs
to the end , play from the front of the list.
Queue implementation
Implementation
*array based (linear or circular)
*pointer based : linked list
ADVANTAGE OF LINKED LIST OVER ARRAY
• Linked list provides two advantages over array
*Dynamic memory allocation.
*Ease of insertion and deletion.
THERE ARE TWO OPERATIONS ON QUEUE
• ENQUEUE(INSERTION AT REAR)
• DEQUEUE(DELETION FROM FRONT)
ENQUEUE
Placing an item in a queue is called “insertion or
enqueue”, which is done at the end of the queue called
“rear”.
DEQUEUE
Removing an item from a queue is called “deletion or
dequeue”, which is done at the other end of the queue
called “front”.
IMPLEMENTATION OF QUEUE USING SINGlY
LINKED LIST
• Create queue implementation using linked list
struct queue
{
int data ;
struct queue *next;
}
data next
Create queue implementation using singly linked
list
struct queue *front = NULL;
struct queue *rear = NULL;
NULL
NULL
front
rear
Enqueue
If there is no node present in the queue
enqueue(ptrf, ptrr)
{
if(ptrf==NULL)
{
ptrf=newnode;
ptrr=newnode;
newnode->next = NULL;
}
}
FRONT REAR
newnode
Enqueue
• If there is one node and multiple node in the queue
ptrr->next = newnode;
newnode->next = NULL;
ptrr = newnode;
front rear
New node
After insertion of a node in the queue
• If there is one node and multiple node in the queue
newnode
Dequeue
• If there is no node in the queue.
• Message should be prompted to the user.
Dequeue(ptrf, ptrr)
{
if(ptrf==NULL)
{
printf("n there is no data present in the queue");
}
}
front rear
Continue…
• If there is one node available in the queue.
• temp=ptrf
if(temp->next ==NULL)
{
ptrf = NULL;
ptrr =NULL;
free(temp);
}
temp
front rear
Continue…
• If there are multiple node in the queue.
• temp=ptrf
ptrf= temp->next;
free(temp)
front rear
temp
x y
After deletion
 .
y
front rear
IMPLEMENTATION OF QUEUE USING DOUBLY
LINKED LIST
• Create queue implementation using doubly linked list
Struct queue
{
int data ;
struct queue *next;
struct queue *prev;
}
prev data next
Create queue implementation using doubly
linked list
struct queue *front = NULL;
struct queue *rear = NULL;
NULL
NULL
front
rear
Enqueue
If there is no node in the linked list.
We need to change the front and rear pointer.
if(ptrf==NULL)
{
ptrf = newnode;
ptrr = newnode;
newnode->next = NULL;
newnode->prev = NULL;
}
front rear
Continue…
• If there is one or multiple node in the queue.
(ptrr)->next= newnode;
newnode->prev = ptrr;
newnode->next = NULL;
ptrr = newnode;
front rear
New node
After insertion…
• v
New node
front rear
Dequeue
• If there is no node in the queue.
• We should prompt message .
if(ptrf==NULL)
{
printf("n there is no data present in the
queue");
}
Continue…
• If there is one node in the queue.
if(ptrf->next==NULL)
{
ptrf =NULL
ptrr =NULL
free(temp)
}
temp
Ptrf=temp
front rear
Continue…
• After deleting
front rear
Continue…
• If there are multiple node in the queue.
temp = ptrf;
(temp->next)->prev = NULL;
ptrf = temp->next;
free(temp);
temp
Temp = ptrf
After deleting
• ->
front rear
Time complexity
Singly linked list Doubly linked list
Enqueue(O(1)) Enqueue(O(1))
Dequeue(O(1)) Dequeue(O(1))
Traverse(O(n)) Traverse(O(n))
Travresal is not an easy task Traversal is easy
summary
• Queue is a linear data structure in which insertion is
performed from rear and deletion is performed from
front end .
• A queue is a FIFO based data structure.
• Doubly linked list is more efficient to implement a
queue because of easy traversal.
THANK YOU !

More Related Content

PPTX
Data structure and algorithm using java
PPT
Linked lists
PPT
Linked List
PPTX
Polynomial reppresentation using Linkedlist-Application of LL.pptx
PDF
Java Linked List Tutorial | Edureka
PPTX
Introduction to data structure ppt
PPT
7.data types in c#
Data structure and algorithm using java
Linked lists
Linked List
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Java Linked List Tutorial | Edureka
Introduction to data structure ppt
7.data types in c#

What's hot (20)

PPT
Data Structures with C Linked List
PPTX
heap Sort Algorithm
PPTX
Linked List
PPTX
Inheritance in c++
PPTX
Doubly Linked List
PPT
Data Structure and Algorithms Linked List
PDF
Binary search tree operations
PPSX
Data Structure (Queue)
PPTX
Queue in Data Structure
PPT
Unit 1 introduction to data structure
PPTX
Quick sort-Data Structure
PPTX
Data Structures - Lecture 8 [Sorting Algorithms]
PPTX
PPTX
Sorting in python
PPTX
PPTX
Bfs and Dfs
PPT
Abstract data types
PPTX
My lectures circular queue
PPTX
Abstract Data Types
PPTX
Linked list
Data Structures with C Linked List
heap Sort Algorithm
Linked List
Inheritance in c++
Doubly Linked List
Data Structure and Algorithms Linked List
Binary search tree operations
Data Structure (Queue)
Queue in Data Structure
Unit 1 introduction to data structure
Quick sort-Data Structure
Data Structures - Lecture 8 [Sorting Algorithms]
Sorting in python
Bfs and Dfs
Abstract data types
My lectures circular queue
Abstract Data Types
Linked list
Ad

Similar to Implementation of queue using singly and doubly linked list. (20)

PPTX
Stack and Queue
PDF
Linked List Implementation of Queue in C
PPTX
queue
PPTX
Bsc cs ii dfs u-2 linklist,stack,queue
PPTX
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
PPTX
DS UNIT2QUEUES.pptx
PPT
Lec-07 Queues.ppt queues introduction to queue
PPTX
Data Structures and Agorithm: DS 09 Queue.pptx
PDF
05 queues
PPTX
Mca ii dfs u-3 linklist,stack,queue
PPTX
Bca ii dfs u-2 linklist,stack,queue
PPTX
QueueUsingArray-1.pptxnansbsbssnsnxbxbhs
PDF
Polynomialmotilalanehrunationalinstitute.pdf
PPTX
DS10-QUEUE0000000000000000000000000000000000000.pptx
PPTX
PDF
Stacks and Queues with Linked List.pdf
PPTX
Queue and its operations
PPTX
Queues in data structures
PPTX
6.queue
PPTX
Queue Data Structure with detailed explanation
Stack and Queue
Linked List Implementation of Queue in C
queue
Bsc cs ii dfs u-2 linklist,stack,queue
DSA_Ques ewoifhjerofhefhehfreofheek.pptx
DS UNIT2QUEUES.pptx
Lec-07 Queues.ppt queues introduction to queue
Data Structures and Agorithm: DS 09 Queue.pptx
05 queues
Mca ii dfs u-3 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
QueueUsingArray-1.pptxnansbsbssnsnxbxbhs
Polynomialmotilalanehrunationalinstitute.pdf
DS10-QUEUE0000000000000000000000000000000000000.pptx
Stacks and Queues with Linked List.pdf
Queue and its operations
Queues in data structures
6.queue
Queue Data Structure with detailed explanation
Ad

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
PDF
TR - Agricultural Crops Production NC III.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
Complications of Minimal Access Surgery at WLH
PDF
Classroom Observation Tools for Teachers
PDF
Pre independence Education in Inndia.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PPTX
Pharma ospi slides which help in ospi learning
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
O7-L3 Supply Chain Operations - ICLT Program
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
Physiotherapy_for_Respiratory_and_Cardiac_Problems WEBBER.pdf
TR - Agricultural Crops Production NC III.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Mark Klimek Lecture Notes_240423 revision books _173037.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Complications of Minimal Access Surgery at WLH
Classroom Observation Tools for Teachers
Pre independence Education in Inndia.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Pharmacology of Heart Failure /Pharmacotherapy of CHF
human mycosis Human fungal infections are called human mycosis..pptx
2.FourierTransform-ShortQuestionswithAnswers.pdf
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Pharma ospi slides which help in ospi learning
FourierSeries-QuestionsWithAnswers(Part-A).pdf
VCE English Exam - Section C Student Revision Booklet
O7-L3 Supply Chain Operations - ICLT Program

Implementation of queue using singly and doubly linked list.

  • 1. Implementation of queue using linked list Submitted to Nemi Chandra Rathore HEAD OF THE DEPARTMENT Presented by Balmukund jha Mehul Mohan
  • 2. CONTENTS • What is queue? • Real world examples of queue. • Applications of queue. • Queue implementation. • Advantage of linked list over array. • Operations on queue. • Implementation of queue using singly linked list . • Create queue implementation using singly linked list. • Implementation of queue using doubly linked list. • Create queue implementation using doubly linked list. • Time complexity . • Summary.
  • 3. WHAT IS QUEUE? • Queue is a linear data structure. • It is used for temporary storage of data values. • A new element is added at one end called rear end . • The existing elements deleted from the other end called front end. • First in first out property.
  • 4. Real world example of queue  At bank counter.  People on an escalator.  At ATM machine.  In one-way road.
  • 6. People on an escalator.
  • 9. Application of queue • Queues are widely used as waiting lists for a single shared resource like printer, disk, cpu. • Queues are used to transfer data asynchronously between two processes , e.g., file IO, sockets. • Queue are used as buffers on MP3 players and portable CD players , iPod playlist. • Queues are used in playlist for jukebox to add songs to the end , play from the front of the list.
  • 10. Queue implementation Implementation *array based (linear or circular) *pointer based : linked list
  • 11. ADVANTAGE OF LINKED LIST OVER ARRAY • Linked list provides two advantages over array *Dynamic memory allocation. *Ease of insertion and deletion.
  • 12. THERE ARE TWO OPERATIONS ON QUEUE • ENQUEUE(INSERTION AT REAR) • DEQUEUE(DELETION FROM FRONT)
  • 13. ENQUEUE Placing an item in a queue is called “insertion or enqueue”, which is done at the end of the queue called “rear”.
  • 14. DEQUEUE Removing an item from a queue is called “deletion or dequeue”, which is done at the other end of the queue called “front”.
  • 15. IMPLEMENTATION OF QUEUE USING SINGlY LINKED LIST • Create queue implementation using linked list struct queue { int data ; struct queue *next; } data next
  • 16. Create queue implementation using singly linked list struct queue *front = NULL; struct queue *rear = NULL; NULL NULL front rear
  • 17. Enqueue If there is no node present in the queue enqueue(ptrf, ptrr) { if(ptrf==NULL) { ptrf=newnode; ptrr=newnode; newnode->next = NULL; } } FRONT REAR newnode
  • 18. Enqueue • If there is one node and multiple node in the queue ptrr->next = newnode; newnode->next = NULL; ptrr = newnode; front rear New node
  • 19. After insertion of a node in the queue • If there is one node and multiple node in the queue newnode
  • 20. Dequeue • If there is no node in the queue. • Message should be prompted to the user. Dequeue(ptrf, ptrr) { if(ptrf==NULL) { printf("n there is no data present in the queue"); } } front rear
  • 21. Continue… • If there is one node available in the queue. • temp=ptrf if(temp->next ==NULL) { ptrf = NULL; ptrr =NULL; free(temp); } temp front rear
  • 22. Continue… • If there are multiple node in the queue. • temp=ptrf ptrf= temp->next; free(temp) front rear temp x y
  • 24. IMPLEMENTATION OF QUEUE USING DOUBLY LINKED LIST • Create queue implementation using doubly linked list Struct queue { int data ; struct queue *next; struct queue *prev; } prev data next
  • 25. Create queue implementation using doubly linked list struct queue *front = NULL; struct queue *rear = NULL; NULL NULL front rear
  • 26. Enqueue If there is no node in the linked list. We need to change the front and rear pointer. if(ptrf==NULL) { ptrf = newnode; ptrr = newnode; newnode->next = NULL; newnode->prev = NULL; } front rear
  • 27. Continue… • If there is one or multiple node in the queue. (ptrr)->next= newnode; newnode->prev = ptrr; newnode->next = NULL; ptrr = newnode; front rear New node
  • 28. After insertion… • v New node front rear
  • 29. Dequeue • If there is no node in the queue. • We should prompt message . if(ptrf==NULL) { printf("n there is no data present in the queue"); }
  • 30. Continue… • If there is one node in the queue. if(ptrf->next==NULL) { ptrf =NULL ptrr =NULL free(temp) } temp Ptrf=temp front rear
  • 32. Continue… • If there are multiple node in the queue. temp = ptrf; (temp->next)->prev = NULL; ptrf = temp->next; free(temp); temp Temp = ptrf
  • 34. Time complexity Singly linked list Doubly linked list Enqueue(O(1)) Enqueue(O(1)) Dequeue(O(1)) Dequeue(O(1)) Traverse(O(n)) Traverse(O(n)) Travresal is not an easy task Traversal is easy
  • 35. summary • Queue is a linear data structure in which insertion is performed from rear and deletion is performed from front end . • A queue is a FIFO based data structure. • Doubly linked list is more efficient to implement a queue because of easy traversal.