SlideShare a Scribd company logo
Dr. CHETHAN CHANDRA S BASAVARADDI
B.E., B.Ed., M.Tech., Ph.D., D.Litt., KEA-KSET.,
Associate Professor,
Dept. CSE, School of CS&T,
Faculty of Engineering Technology,
G M University,
Post Box No-4, PB Road,
Davanagere-577006,
 A Queue Data Structure is a fundamental concept in
computer science used for storing and managing
data in a specific order.
 It follows the principle of "First in, First out" (FIFO),
where the first element added to the queue is the
first one to be removed.
 It is used as a buffer in computer systems where we
have speed mismatch between two devices that
communicate with each other. For example, CPU
and keyboard and two devices in a network
 Queue is also used in Operating System algorithms
like CPU Scheduling and Memory Management,
and many standard algorithms like Breadth First
Search of Graph, Level Order Traversal of a Tree.
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
Queue – Linked List Implementation
 Linked List implementation of the queue data structure is
discussed and implemented. Print ‘-1’ if the queue is
empty.
 we maintain two pointers, front and rear. The front points
to the first item of the queue and rear points to the last
item.
 enQueue(): This operation adds a new node after the
rear and moves the rear to the next node.
 deQueue(): This operation removes the front node and
moves the front to the next node.
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
Follow the below steps to solve the problem:
 Create a class Node with data members integer data and Node*
next
 A parameterized constructor that takes an integer x value as a
parameter and sets data equal to x and next as NULL
 Create a class Queue with data members Node front and rear
Enqueue Operation with parameter x:
 Initialize Node* temp with data = x
 If the rear is set to NULL then set the front and rear to temp and
return(Base Case)
 Else set rear next to temp and then move rear to temp
 Dequeue Operation:
If the front is set to NULL return(Base Case)
Initialize Node temp with front and set front to
its next
If the front is equal to NULL then set the rear to
NULL
Delete temp from the memory
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
Data Structures  and Algorithms-DSA_Linkedlist_class 7.pdf
 Time Complexity: O(1), The time complexity of
both operations enqueue() and dequeue() is
O(1) as it only changes a few pointers in both
operations
 Auxiliary Space: O(1), The auxiliary Space of
both operations enqueue() and dequeue() is
O(1) as constant extra space is required

More Related Content

PPTX
Basic Queue Operation in DataStructure.pptx
PPTX
Queue and its operations
PDF
PPTX
queue.pptx
PDF
Polynomialmotilalanehrunationalinstitute.pdf
PPT
Lec-07 Queues.ppt queues introduction to queue
PPTX
@Chapter 4 DSA Part II.pptx
PPTX
VCE Unit 03vv.pptx
Basic Queue Operation in DataStructure.pptx
Queue and its operations
queue.pptx
Polynomialmotilalanehrunationalinstitute.pdf
Lec-07 Queues.ppt queues introduction to queue
@Chapter 4 DSA Part II.pptx
VCE Unit 03vv.pptx

Similar to Data Structures and Algorithms-DSA_Linkedlist_class 7.pdf (20)

PPTX
Queues
PPTX
PPTX
Data structures
PDF
Lab 07 (2).pdfbdvdyve dhdysbsnjsnsvdvydbdns
PPTX
Stack and queue
PDF
Basic Terminologies of Queue...Basic operations on Queue
PPTX
queues.pptx
PPT
Queues in C++ detailed explanation and examples .ppt
PPTX
Queues_0748555555555555555555555526.pptx
PPTX
DS ppt1.pptx.c programing. Engineering. Data structure
PPTX
Bsc cs ii dfs u-2 linklist,stack,queue
PPTX
The presention is about the queue data structure
PPTX
Bca ii dfs u-2 linklist,stack,queue
PPTX
QUEUE in data-structure (classification, working procedure, Applications)
PDF
Queue in data structure
PPTX
Chapter 4 data structure and algorithm - Stacks and Queues
PPTX
Data structure , stack , queue
PPTX
PDF
05 queues
PPTX
Queues
Data structures
Lab 07 (2).pdfbdvdyve dhdysbsnjsnsvdvydbdns
Stack and queue
Basic Terminologies of Queue...Basic operations on Queue
queues.pptx
Queues in C++ detailed explanation and examples .ppt
Queues_0748555555555555555555555526.pptx
DS ppt1.pptx.c programing. Engineering. Data structure
Bsc cs ii dfs u-2 linklist,stack,queue
The presention is about the queue data structure
Bca ii dfs u-2 linklist,stack,queue
QUEUE in data-structure (classification, working procedure, Applications)
Queue in data structure
Chapter 4 data structure and algorithm - Stacks and Queues
Data structure , stack , queue
05 queues
Ad

More from Chethan Raddi (7)

PDF
Data Structures and Algorithms-DSA_Linkedlist_class 8.pdf
PDF
Data Structures and Algorithms-DSA_Linkedlist_class 6.pdf
PDF
Data Structures and Algorithms-DSA_Linkedlist_class 3.pdf
PDF
Data Structures and Algorithms-DSA_Linkedlist_class 4.pdf
PDF
Data Structures and Algorithms-DSA_Linkedlist_class 2.pdf
PDF
Data Structures and Algorithms-DSA_Linkedlist_class 5.pdf
PDF
Data Structures and Algorithms-DSA_Linkedlist_class 1.pdf
Data Structures and Algorithms-DSA_Linkedlist_class 8.pdf
Data Structures and Algorithms-DSA_Linkedlist_class 6.pdf
Data Structures and Algorithms-DSA_Linkedlist_class 3.pdf
Data Structures and Algorithms-DSA_Linkedlist_class 4.pdf
Data Structures and Algorithms-DSA_Linkedlist_class 2.pdf
Data Structures and Algorithms-DSA_Linkedlist_class 5.pdf
Data Structures and Algorithms-DSA_Linkedlist_class 1.pdf
Ad

Recently uploaded (20)

PPTX
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
PPT
Drone Technology Electronics components_1
PDF
composite construction of structures.pdf
PPTX
web development for engineering and engineering
PPTX
Strings in CPP - Strings in C++ are sequences of characters used to store and...
PPTX
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
PDF
Operating System & Kernel Study Guide-1 - converted.pdf
PPTX
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
PPTX
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
PDF
ETO & MEO Certificate of Competency Questions and Answers
PPTX
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
PPTX
UNIT-1 - COAL BASED THERMAL POWER PLANTS
PPTX
Lecture Notes Electrical Wiring System Components
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
bas. eng. economics group 4 presentation 1.pptx
PPTX
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
PDF
Arduino robotics embedded978-1-4302-3184-4.pdf
PDF
Embodied AI: Ushering in the Next Era of Intelligent Systems
PPTX
Practice Questions on recent development part 1.pptx
Fluid Mechanics, Module 3: Basics of Fluid Mechanics
Drone Technology Electronics components_1
composite construction of structures.pdf
web development for engineering and engineering
Strings in CPP - Strings in C++ are sequences of characters used to store and...
The-Looming-Shadow-How-AI-Poses-Dangers-to-Humanity.pptx
Operating System & Kernel Study Guide-1 - converted.pdf
Infosys Presentation by1.Riyan Bagwan 2.Samadhan Naiknavare 3.Gaurav Shinde 4...
M Tech Sem 1 Civil Engineering Environmental Sciences.pptx
ETO & MEO Certificate of Competency Questions and Answers
FINAL REVIEW FOR COPD DIANOSIS FOR PULMONARY DISEASE.pptx
UNIT-1 - COAL BASED THERMAL POWER PLANTS
Lecture Notes Electrical Wiring System Components
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
bas. eng. economics group 4 presentation 1.pptx
MCN 401 KTU-2019-PPE KITS-MODULE 2.pptx
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
Arduino robotics embedded978-1-4302-3184-4.pdf
Embodied AI: Ushering in the Next Era of Intelligent Systems
Practice Questions on recent development part 1.pptx

Data Structures and Algorithms-DSA_Linkedlist_class 7.pdf

  • 1. Dr. CHETHAN CHANDRA S BASAVARADDI B.E., B.Ed., M.Tech., Ph.D., D.Litt., KEA-KSET., Associate Professor, Dept. CSE, School of CS&T, Faculty of Engineering Technology, G M University, Post Box No-4, PB Road, Davanagere-577006,
  • 2.  A Queue Data Structure is a fundamental concept in computer science used for storing and managing data in a specific order.  It follows the principle of "First in, First out" (FIFO), where the first element added to the queue is the first one to be removed.  It is used as a buffer in computer systems where we have speed mismatch between two devices that communicate with each other. For example, CPU and keyboard and two devices in a network  Queue is also used in Operating System algorithms like CPU Scheduling and Memory Management, and many standard algorithms like Breadth First Search of Graph, Level Order Traversal of a Tree.
  • 4. Queue – Linked List Implementation  Linked List implementation of the queue data structure is discussed and implemented. Print ‘-1’ if the queue is empty.  we maintain two pointers, front and rear. The front points to the first item of the queue and rear points to the last item.  enQueue(): This operation adds a new node after the rear and moves the rear to the next node.  deQueue(): This operation removes the front node and moves the front to the next node.
  • 6. Follow the below steps to solve the problem:  Create a class Node with data members integer data and Node* next  A parameterized constructor that takes an integer x value as a parameter and sets data equal to x and next as NULL  Create a class Queue with data members Node front and rear Enqueue Operation with parameter x:  Initialize Node* temp with data = x  If the rear is set to NULL then set the front and rear to temp and return(Base Case)  Else set rear next to temp and then move rear to temp
  • 7.  Dequeue Operation: If the front is set to NULL return(Base Case) Initialize Node temp with front and set front to its next If the front is equal to NULL then set the rear to NULL Delete temp from the memory
  • 15.  Time Complexity: O(1), The time complexity of both operations enqueue() and dequeue() is O(1) as it only changes a few pointers in both operations  Auxiliary Space: O(1), The auxiliary Space of both operations enqueue() and dequeue() is O(1) as constant extra space is required