SlideShare a Scribd company logo
Data Structures &
Algorithms
Chapter 3: Linkedlist
Data Structures
Chapter Three :Linked Lists
 Linked List can be defined as collection of objects
called nodes that are randomly stored in the
memory.
 A linked list is a linear collection of data elements.
These data elements are called nodes.
 A node contains two fields i.e. data stored at that
particular address and the pointer which contains
the address of the next node in the memory.
 The last node of the list contains pointer to the null.
Example of Simple Linked Lists
Arrays VS Linked Lists
SINGLY LINKED Lists
A singly linked list is the simplest type of linked
list in which every node contains some data and
a pointer to the next node of the same data
type. By saying that the node contains a pointer
to the next node, we mean that the node stores
the address of the next node in sequence.
A singly linked list allows traversal of data only
in one way.
Operations of SINGLY LINKED Lists
Traversing a Linked List
Searching for a Value in a Linked List
Inserting a New Node in a Linked List
 Case 1: The new node is inserted at the beginning.
 Case 2: The new node is inserted at the end.
 Case 3: The new node is inserted after a given node.
 Case 4: The new node is inserted before a given node.
 Deleting a Node from a Linked List
 Case 1: The first node is deleted.
 Case 2: The last node is deleted.
 Case 3: The node after a given node is deleted.
Traversing a Linked List
Traversing a linked list means accessing the nodes
of the list in order to perform some processing on
them. Remember a linked list always contains a
pointer variable START which stores the address
of the first node of the list. End of the list is marked
by storing NULL or –1 in the NEXT field of the last
node.
For traversing the linked list, we also make use of
another pointer variable PTR which points to the
node that is currently being accessed.
Algorithm for traversing a linked list
 Step 1: [INITIALIZE] SET PTR = START
 Step 2: Repeat Steps 3 and 4 while PTR
!= NULL
 Step 3: Apply Process to PTR DATA
 Step 4: SET PTR = PTR NEXT
 [END OF LOOP]
 Step 5: EXIT
Searching for a Value in a Linked List
Searching a linked list means to find a particular
element in the linked list. As already discussed,
a linked list consists of nodes which are divided
into two parts, the information part and the next
part. So searching means finding whether a
given value is present in the information part of
the node or not. If it is present, the algorithm
returns the address of the node that contains
the value.
Algorithm to search a linked list
 Step 1: [INITIALIZE] SET PTR = START
 Step 2: Repeat Step 3 while PTR != NULL
 Step 3: IF VAL = PTR DATA
 SET POS = PTR
 Go To Step 5
 ELSE
 SET PTR = PTR NEXT
 [END OF IF]
 [END OF LOOP]
 Step 4: SET POS = NULL
 Step 5: EXIT
Example If we have VAL = 4, then the flow of the
algorithm can be explained as shown in the
figure.
Inserting a New Node in a Linked List
In this section, we will see how a new node is added
into an already existing linked list. We will
 take four cases and then see how insertion is done
in each case.
 Case 1: The new node is inserted at the beginning.
 Case 2: The new node is inserted at the end.
 Case 3: The new node is inserted after a given
node.
 Case 4: The new node is inserted before a given
node.
Inserting a Node at the Beginning of a Linked List
Consider the linked list shown in Fig. 6.12. Suppose
we want to add a new node with data 9 and add it as
the first node of the list. Then the following changes
will be done in the linked list.
Inserting a Node at the End of a Linked List
Suppose we want to add a new node with
data 9 as the last node of the list.
Inserting a Node After a Given Node in a Linked List
Suppose we want to add a new node with value
9 after the node containing data 3.
Inserting a Node Before a Given Node in a Linked List
Suppose we want to add a new node with value 9
beforethe node containing 3.
Deleting a Node from a Linked List
In this section, we will discuss how a node
is deleted from an already existing linked
list. We will
 consider three cases and then see how
deletion is done in each case.
 Case 1: The first node is deleted.
 Case 2: The last node is deleted.
 Case 3: The node after a given node is
deleted.
Deleting the First Node from a Linked List
When we want to delete a node from the
beginning of the list, then the following changes
will be done in the linked list.
Algorithm to delete the first Node
 Step 1: IF START = NULL
 Write UNDERFLOW
 Go to Step 5
 [END OF IF]
 Step 2: SET PTR = START
 Step 3: SET START = START NEXT
 Step 4: FREE PTR
 Step 5: EXIT
Deleting the Last Node from a Linked List
Suppose we want to delete the last node from the
linked list, then the following changes will be done
in the linked list.
Algorithm to delete the last node
 Step 1: IF START = NULL Write UNDERFLOW
 Go to Step 8
 [END OF IF]
 Step 2: SET PTR = START
 Step 3: Repeat Steps 4 and 5 while PTR NEXT != NULL
 Step 4: SET PREPTR = PTR
 Step 5: SET PTR = PTR NEXT
 [END OF LOOP]
 Step 6: SET PREPTR NEXT = NULL
 Step 7: FREE PTR
 Step 8: EXIT
Deleting the Node After a Given Node in a Linked List
Suppose we want to delete the node that succeeds the
node which contains data value 4. Then the following
changes will be done in the linked list.
Algorithm to delete the node after a given node
 Step 1: IF START = NULL
 Write UNDERFLOW
 Go to Step 10
 [END OF IF]
 Step 2: SET PTR = START
 Step 3: SET PREPTR = PTR
 Step 4: Repeat Steps 5 and 6 while PREPTR DATA != NUll
 Step 5: SET PREPTR = PTR
 Step 6: SET PTR = PTR NEXT
 [END OF LOOP]
 Step 7: SET TEMP = PTR
 Step 8: SET PREPTR NEXT = PTR NEXT
 Step 9: FREE TEMP
 Step 10 : EXIT
CIRCULAR LINKED LISTS
 CIRCULAR linked list is a linked data structure
that consists of a set of sequentially linked
records called nodes. Each node contains three
fields ::
 One is data part which contain data only.
 Two other field is links part that are point
 or references to the previous or to the next
node in the sequence of nodes.
Chapter 3 Linkedlist Data Structure .pdf
Inserting a New Node in a Circular Linked List
In this section, we will see how a new node
is added into an already existing linked list.
We will take two cases and then see how
insertion is done in each case.
 Case 1: The new node is inserted at the
beginning of the circular linked list.
 Case 2: The new node is inserted at the
end of the circular linked list.
Inserting a Node at the Beginning of a Circular Linked List
Suppose we want to add a new node with data 9 as
the first node of the list. Then the following changes
will be done in the linked list.
Inserting a Node at the End of a Circular Linked List
Suppose we want to add a new node with data 9 as the last
node of the list. Then the following changes will be done in the
linked list.
Deleting a Node from a Circular Linked List
 In this section, we will discuss how a node is
deleted from an already existing circular linked
list. We will take two cases and then see how
deletion is done in each case. Rest of the cases
of deletion are same as that given for singly
linked lists.
 Case 1: The first node is deleted.
 Case 2: The last node is deleted.
Deleting the First Node from a Circular Linked List
Consider the circular linked list shown in Fig. 6.33. When
we want to delete a node from the beginning of the list,
then the following changes will be done in the linked list.
Deleting the Last Node from a Circular Linked List
Consider the circular linked list shown in Fig. 6.35.
Suppose we want to delete the last node from the linked
list, then the following changes will be done in the linked
list.
DOUBLY LINKED LISTS
A doubly linked list or a two-way linked list is a
more complex type of linked list which contains
a pointer to the next as well as the previous node
in the sequence. Therefore, it consists of three
parts—data, a pointer to the next node, and a
pointer to the previous node as shown in Fig.
6.37.
Inserting a New Node in a Doubly Linked List
 In this section, we will discuss how a new node
is added into an already existing doubly linked
list. We will take four cases and then see how
insertion is done in each case.
 Case 1: The new node is inserted at the
beginning.
 Case 2: The new node is inserted at the end.
 Case 3: The new node is inserted after a given
node.
 Case 4: The new node is inserted before a
given node.
Inserting a Node at the Beginning of a Doubly Linked List
Consider the doubly linked list shown in Fig.
6.39. Suppose we want to add a new node with
data 9 as the first node of the list. Then the
following changes will be done in the linked list.
Inserting a Node at the End of a Doubly Linked List
Consider the doubly linked list shown in Fig. 6.41. Suppose
we want to add a new node with data 9 as the last node of the
list. Then the following changes will be done in the linked list.
Inserting a Node After a Given Node in a Doubly Linked List
Suppose we want to add a new node with
value 9 after the node containing 3. Before discussing
the changes that will be done in the linked
List.
Inserting a Node Before a Given Node in a Doubly Linked List
Consider the doubly linked list shown in Fig. 6.46. Suppose we
want to add a new node with value 9 before the node containing 3.
Deleting a Node from a Doubly Linked List
In this section, we will see how a node is
deleted from an already existing doubly linked
list. We will take four cases and then see how
deletion is done in each case.
 Case 1: The first node is deleted.
 Case 2: The last node is deleted.
 Case 3: The node after a given node is deleted.
Deleting the First Node from a Doubly Linked List
Deleting the Node After a Given Node in a Doubly Linked List
END

More Related Content

PPTX
linked list in data structure
shameen khan
 
PPTX
IPv4 Addressing
TheGodfather HA
 
PDF
Logic programming (1)
Nitesh Singh
 
PPTX
ITIL Service Transition
Marvin Sirait
 
PDF
AI3391 ARTIFICIAL INTELLIGENCE UNIT II notes.pdf
Guru Nanak Technical Institutions
 
PDF
Functional Dependency
Alaanoor94
 
DOCX
AI Lab Manual.docx
KPRevathiAsstprofITD
 
linked list in data structure
shameen khan
 
IPv4 Addressing
TheGodfather HA
 
Logic programming (1)
Nitesh Singh
 
ITIL Service Transition
Marvin Sirait
 
AI3391 ARTIFICIAL INTELLIGENCE UNIT II notes.pdf
Guru Nanak Technical Institutions
 
Functional Dependency
Alaanoor94
 
AI Lab Manual.docx
KPRevathiAsstprofITD
 

What's hot (20)

PPTX
Bubble sort | Data structure |
MdSaiful14
 
PDF
Selection sort
Abdelrahman Saleh
 
PDF
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
PPTX
Searching techniques in Data Structure And Algorithm
03446940736
 
PPTX
Doubly Linked List || Operations || Algorithms
Shubham Sharma
 
PPT
minimum spanning tree
Melaku Bayih Demessie
 
PPTX
Data Structures (CS8391)
Elavarasi K
 
PDF
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
PPT
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
PPT
Bubble sort
Manek Ar
 
PPTX
Linear Search Data Structure
Talha Shaikh
 
PPTX
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Albin562191
 
PPTX
Two dimensional arrays
Neeru Mittal
 
PPT
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
Sahil Kumar
 
PPTX
9 big o-notation
irdginfo
 
PPTX
Searching
Ashim Lamichhane
 
PPTX
Hashing
LavanyaJ28
 
PPTX
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
Bubble sort | Data structure |
MdSaiful14
 
Selection sort
Abdelrahman Saleh
 
BCA DATA STRUCTURES LINEAR ARRAYS MRS.SOWMYA JYOTHI
Sowmya Jyothi
 
Searching techniques in Data Structure And Algorithm
03446940736
 
Doubly Linked List || Operations || Algorithms
Shubham Sharma
 
minimum spanning tree
Melaku Bayih Demessie
 
Data Structures (CS8391)
Elavarasi K
 
Algorithms Lecture 4: Sorting Algorithms I
Mohamed Loey
 
SEARCHING AND SORTING ALGORITHMS
Gokul Hari
 
Bubble sort
Manek Ar
 
Linear Search Data Structure
Talha Shaikh
 
Polynomial reppresentation using Linkedlist-Application of LL.pptx
Albin562191
 
Two dimensional arrays
Neeru Mittal
 
ADA - Minimum Spanning Tree Prim Kruskal and Dijkstra
Sahil Kumar
 
9 big o-notation
irdginfo
 
Searching
Ashim Lamichhane
 
Hashing
LavanyaJ28
 
Analysis of Algorithm - Binary Search.pptx
Maulana Abul Kalam Azad University of Technology
 
Ad

Similar to Chapter 3 Linkedlist Data Structure .pdf (20)

PPTX
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
PPTX
Linked List Representation of a Linked List.pptx
AAUsH2
 
PPT
Operations on linked list
Sumathi Kv
 
PPT
ds 4Linked lists.ppt
AlliVinay1
 
PPTX
linked list in dsa python (presentation)
MirzaAbdullahTariq
 
PPT
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
PPT
Data Structure and Algorithms Linked List
ManishPrajapati78
 
PPTX
linked list.pptxdj bdjbhjddnbfjdndvdhbfvgh
ssusere1e8b7
 
PPTX
CH4.pptx
mohamedOsmaanFG
 
PPTX
Lec3-Linked list.pptx
FaheemMahmood2
 
PPTX
Linked list in Data Structure and Algorithm
KristinaBorooah
 
PPTX
Linked List Presentation in data structurepptx
nikhilcse1
 
PPT
linked_lists.ppt linked_lists linked_lists
AmsaAzeem
 
PPTX
1.3 Linked List.pptx
ssuserd2f031
 
PPT
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
PPT
List Data Structure
Zidny Nafan
 
PPT
List data structure
Mahmoud Abuwarda
 
PPT
linked list1.ppt linked list ppts and notes
nisharaheja1986
 
PPTX
link list.pptx complete notes detailed ans
IqraHanif27
 
PPTX
RPT_03_A_Linked List presentation for FE
AshishFamt
 
Engineering.CSE.DataStructure.Linkedlist.notes
limev72215
 
Linked List Representation of a Linked List.pptx
AAUsH2
 
Operations on linked list
Sumathi Kv
 
ds 4Linked lists.ppt
AlliVinay1
 
linked list in dsa python (presentation)
MirzaAbdullahTariq
 
Algo>ADT list & linked list
Ain-ul-Moiz Khawaja
 
Data Structure and Algorithms Linked List
ManishPrajapati78
 
linked list.pptxdj bdjbhjddnbfjdndvdhbfvgh
ssusere1e8b7
 
CH4.pptx
mohamedOsmaanFG
 
Lec3-Linked list.pptx
FaheemMahmood2
 
Linked list in Data Structure and Algorithm
KristinaBorooah
 
Linked List Presentation in data structurepptx
nikhilcse1
 
linked_lists.ppt linked_lists linked_lists
AmsaAzeem
 
1.3 Linked List.pptx
ssuserd2f031
 
Lecture 3 List of Data Structures & Algorithms
haseebanjum2611
 
List Data Structure
Zidny Nafan
 
List data structure
Mahmoud Abuwarda
 
linked list1.ppt linked list ppts and notes
nisharaheja1986
 
link list.pptx complete notes detailed ans
IqraHanif27
 
RPT_03_A_Linked List presentation for FE
AshishFamt
 
Ad

Recently uploaded (20)

PPTX
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
PDF
Chad Readey - An Independent Thinker
Chad Readey
 
PDF
Company Profile 2023 PT. ZEKON INDONESIA.pdf
hendranofriadi26
 
PDF
Linux OS guide to know, operate. Linux Filesystem, command, users and system
Kiran Maharjan
 
PPTX
Logistic Regression ml machine learning.pptx
abdullahcocindia
 
PPTX
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
PDF
Master Databricks SQL with AccentFuture – The Future of Data Warehousing
Accentfuture
 
PPTX
Trading Procedures (1).pptxcffcdddxxddsss
garv794
 
PPTX
GR3-PPTFINAL (1).pptx 0.91 MbHIHUHUGG,HJGH
DarylArellaga1
 
PPTX
batch data Retailer Data management Project.pptx
sumitmundhe77
 
PDF
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
PDF
Digital Infrastructure – Powering the Connected Age
Heera Yadav
 
PDF
Data Science Trends & Career Guide---ppt
jisajoy3061
 
PDF
Research about a FoodFolio app for personalized dietary tracking and health o...
AustinLiamAndres
 
PDF
Taxes Foundatisdcsdcsdon Certificate.pdf
PratyushPrem2
 
PPTX
Presentation1.pptxvhhh. H ycycyyccycycvvv
ItratBatool16
 
PPTX
Complete_STATA_Introduction_Beginner.pptx
mbayekebe
 
PPTX
Measurement of Afordability for Water Supply and Sanitation in Bangladesh .pptx
akmibrahimbd
 
PPT
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
JanakiRaman206018
 
PDF
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 
Introduction to Biostatistics Presentation.pptx
AtemJoshua
 
Chad Readey - An Independent Thinker
Chad Readey
 
Company Profile 2023 PT. ZEKON INDONESIA.pdf
hendranofriadi26
 
Linux OS guide to know, operate. Linux Filesystem, command, users and system
Kiran Maharjan
 
Logistic Regression ml machine learning.pptx
abdullahcocindia
 
Data-Driven Machine Learning for Rail Infrastructure Health Monitoring
Sione Palu
 
Master Databricks SQL with AccentFuture – The Future of Data Warehousing
Accentfuture
 
Trading Procedures (1).pptxcffcdddxxddsss
garv794
 
GR3-PPTFINAL (1).pptx 0.91 MbHIHUHUGG,HJGH
DarylArellaga1
 
batch data Retailer Data management Project.pptx
sumitmundhe77
 
TIC ACTIVIDAD 1geeeeeeeeeeeeeeeeeeeeeeeeeeeeeer3.pdf
Thais Ruiz
 
Digital Infrastructure – Powering the Connected Age
Heera Yadav
 
Data Science Trends & Career Guide---ppt
jisajoy3061
 
Research about a FoodFolio app for personalized dietary tracking and health o...
AustinLiamAndres
 
Taxes Foundatisdcsdcsdon Certificate.pdf
PratyushPrem2
 
Presentation1.pptxvhhh. H ycycyyccycycvvv
ItratBatool16
 
Complete_STATA_Introduction_Beginner.pptx
mbayekebe
 
Measurement of Afordability for Water Supply and Sanitation in Bangladesh .pptx
akmibrahimbd
 
Chapter 3 METAL JOINING.pptnnnnnnnnnnnnn
JanakiRaman206018
 
The_Future_of_Data_Analytics_by_CA_Suvidha_Chaplot_UPDATED.pdf
CA Suvidha Chaplot
 

Chapter 3 Linkedlist Data Structure .pdf

  • 1. Data Structures & Algorithms Chapter 3: Linkedlist Data Structures
  • 2. Chapter Three :Linked Lists  Linked List can be defined as collection of objects called nodes that are randomly stored in the memory.  A linked list is a linear collection of data elements. These data elements are called nodes.  A node contains two fields i.e. data stored at that particular address and the pointer which contains the address of the next node in the memory.  The last node of the list contains pointer to the null.
  • 3. Example of Simple Linked Lists
  • 5. SINGLY LINKED Lists A singly linked list is the simplest type of linked list in which every node contains some data and a pointer to the next node of the same data type. By saying that the node contains a pointer to the next node, we mean that the node stores the address of the next node in sequence. A singly linked list allows traversal of data only in one way.
  • 6. Operations of SINGLY LINKED Lists Traversing a Linked List Searching for a Value in a Linked List Inserting a New Node in a Linked List  Case 1: The new node is inserted at the beginning.  Case 2: The new node is inserted at the end.  Case 3: The new node is inserted after a given node.  Case 4: The new node is inserted before a given node.  Deleting a Node from a Linked List  Case 1: The first node is deleted.  Case 2: The last node is deleted.  Case 3: The node after a given node is deleted.
  • 7. Traversing a Linked List Traversing a linked list means accessing the nodes of the list in order to perform some processing on them. Remember a linked list always contains a pointer variable START which stores the address of the first node of the list. End of the list is marked by storing NULL or –1 in the NEXT field of the last node. For traversing the linked list, we also make use of another pointer variable PTR which points to the node that is currently being accessed.
  • 8. Algorithm for traversing a linked list  Step 1: [INITIALIZE] SET PTR = START  Step 2: Repeat Steps 3 and 4 while PTR != NULL  Step 3: Apply Process to PTR DATA  Step 4: SET PTR = PTR NEXT  [END OF LOOP]  Step 5: EXIT
  • 9. Searching for a Value in a Linked List Searching a linked list means to find a particular element in the linked list. As already discussed, a linked list consists of nodes which are divided into two parts, the information part and the next part. So searching means finding whether a given value is present in the information part of the node or not. If it is present, the algorithm returns the address of the node that contains the value.
  • 10. Algorithm to search a linked list  Step 1: [INITIALIZE] SET PTR = START  Step 2: Repeat Step 3 while PTR != NULL  Step 3: IF VAL = PTR DATA  SET POS = PTR  Go To Step 5  ELSE  SET PTR = PTR NEXT  [END OF IF]  [END OF LOOP]  Step 4: SET POS = NULL  Step 5: EXIT
  • 11. Example If we have VAL = 4, then the flow of the algorithm can be explained as shown in the figure.
  • 12. Inserting a New Node in a Linked List In this section, we will see how a new node is added into an already existing linked list. We will  take four cases and then see how insertion is done in each case.  Case 1: The new node is inserted at the beginning.  Case 2: The new node is inserted at the end.  Case 3: The new node is inserted after a given node.  Case 4: The new node is inserted before a given node.
  • 13. Inserting a Node at the Beginning of a Linked List Consider the linked list shown in Fig. 6.12. Suppose we want to add a new node with data 9 and add it as the first node of the list. Then the following changes will be done in the linked list.
  • 14. Inserting a Node at the End of a Linked List Suppose we want to add a new node with data 9 as the last node of the list.
  • 15. Inserting a Node After a Given Node in a Linked List Suppose we want to add a new node with value 9 after the node containing data 3.
  • 16. Inserting a Node Before a Given Node in a Linked List Suppose we want to add a new node with value 9 beforethe node containing 3.
  • 17. Deleting a Node from a Linked List In this section, we will discuss how a node is deleted from an already existing linked list. We will  consider three cases and then see how deletion is done in each case.  Case 1: The first node is deleted.  Case 2: The last node is deleted.  Case 3: The node after a given node is deleted.
  • 18. Deleting the First Node from a Linked List When we want to delete a node from the beginning of the list, then the following changes will be done in the linked list.
  • 19. Algorithm to delete the first Node  Step 1: IF START = NULL  Write UNDERFLOW  Go to Step 5  [END OF IF]  Step 2: SET PTR = START  Step 3: SET START = START NEXT  Step 4: FREE PTR  Step 5: EXIT
  • 20. Deleting the Last Node from a Linked List Suppose we want to delete the last node from the linked list, then the following changes will be done in the linked list.
  • 21. Algorithm to delete the last node  Step 1: IF START = NULL Write UNDERFLOW  Go to Step 8  [END OF IF]  Step 2: SET PTR = START  Step 3: Repeat Steps 4 and 5 while PTR NEXT != NULL  Step 4: SET PREPTR = PTR  Step 5: SET PTR = PTR NEXT  [END OF LOOP]  Step 6: SET PREPTR NEXT = NULL  Step 7: FREE PTR  Step 8: EXIT
  • 22. Deleting the Node After a Given Node in a Linked List Suppose we want to delete the node that succeeds the node which contains data value 4. Then the following changes will be done in the linked list.
  • 23. Algorithm to delete the node after a given node  Step 1: IF START = NULL  Write UNDERFLOW  Go to Step 10  [END OF IF]  Step 2: SET PTR = START  Step 3: SET PREPTR = PTR  Step 4: Repeat Steps 5 and 6 while PREPTR DATA != NUll  Step 5: SET PREPTR = PTR  Step 6: SET PTR = PTR NEXT  [END OF LOOP]  Step 7: SET TEMP = PTR  Step 8: SET PREPTR NEXT = PTR NEXT  Step 9: FREE TEMP  Step 10 : EXIT
  • 24. CIRCULAR LINKED LISTS  CIRCULAR linked list is a linked data structure that consists of a set of sequentially linked records called nodes. Each node contains three fields ::  One is data part which contain data only.  Two other field is links part that are point  or references to the previous or to the next node in the sequence of nodes.
  • 26. Inserting a New Node in a Circular Linked List In this section, we will see how a new node is added into an already existing linked list. We will take two cases and then see how insertion is done in each case.  Case 1: The new node is inserted at the beginning of the circular linked list.  Case 2: The new node is inserted at the end of the circular linked list.
  • 27. Inserting a Node at the Beginning of a Circular Linked List Suppose we want to add a new node with data 9 as the first node of the list. Then the following changes will be done in the linked list.
  • 28. Inserting a Node at the End of a Circular Linked List Suppose we want to add a new node with data 9 as the last node of the list. Then the following changes will be done in the linked list.
  • 29. Deleting a Node from a Circular Linked List  In this section, we will discuss how a node is deleted from an already existing circular linked list. We will take two cases and then see how deletion is done in each case. Rest of the cases of deletion are same as that given for singly linked lists.  Case 1: The first node is deleted.  Case 2: The last node is deleted.
  • 30. Deleting the First Node from a Circular Linked List Consider the circular linked list shown in Fig. 6.33. When we want to delete a node from the beginning of the list, then the following changes will be done in the linked list.
  • 31. Deleting the Last Node from a Circular Linked List Consider the circular linked list shown in Fig. 6.35. Suppose we want to delete the last node from the linked list, then the following changes will be done in the linked list.
  • 32. DOUBLY LINKED LISTS A doubly linked list or a two-way linked list is a more complex type of linked list which contains a pointer to the next as well as the previous node in the sequence. Therefore, it consists of three parts—data, a pointer to the next node, and a pointer to the previous node as shown in Fig. 6.37.
  • 33. Inserting a New Node in a Doubly Linked List  In this section, we will discuss how a new node is added into an already existing doubly linked list. We will take four cases and then see how insertion is done in each case.  Case 1: The new node is inserted at the beginning.  Case 2: The new node is inserted at the end.  Case 3: The new node is inserted after a given node.  Case 4: The new node is inserted before a given node.
  • 34. Inserting a Node at the Beginning of a Doubly Linked List Consider the doubly linked list shown in Fig. 6.39. Suppose we want to add a new node with data 9 as the first node of the list. Then the following changes will be done in the linked list.
  • 35. Inserting a Node at the End of a Doubly Linked List Consider the doubly linked list shown in Fig. 6.41. Suppose we want to add a new node with data 9 as the last node of the list. Then the following changes will be done in the linked list.
  • 36. Inserting a Node After a Given Node in a Doubly Linked List Suppose we want to add a new node with value 9 after the node containing 3. Before discussing the changes that will be done in the linked List.
  • 37. Inserting a Node Before a Given Node in a Doubly Linked List Consider the doubly linked list shown in Fig. 6.46. Suppose we want to add a new node with value 9 before the node containing 3.
  • 38. Deleting a Node from a Doubly Linked List In this section, we will see how a node is deleted from an already existing doubly linked list. We will take four cases and then see how deletion is done in each case.  Case 1: The first node is deleted.  Case 2: The last node is deleted.  Case 3: The node after a given node is deleted.
  • 39. Deleting the First Node from a Doubly Linked List
  • 40. Deleting the Node After a Given Node in a Doubly Linked List
  • 41. END