SlideShare a Scribd company logo
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
1
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 Recognize need of a Data Structure, which Dynamically
can Shrink and Grow
 Realization of Linked List as Dynamic Data StructureTo
understand the well-defined, clear, and simple approach of
program design
 Utilize Flexibility of the same Easily and EffectivelyTo
understand sequential organization of data
 Learn Variations of Linked List and Use them for
Appropriate Applications
2
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
3
 The linked list is a very effective and efficient dynamic
data structure
 Data items can be stored anywhere in memory in a
scattered manner
 To maintain the specific sequence of these data items we
need to maintain link(s) with successor (and/ or
predecessor)
 It is called as a linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 A linked list is an ordered collection of data in which each
element contains minimum two values, data and
link(s) to its successor (and/ or predecessor)
 The list with one link field using which every element is
associated to either its predecessor or successor is called
as singly linked list
 In a linked list, before adding any element to the list,
memory space for that node must be allocated
 A link is kept with each item to the next item in the list
4
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
5
Fig: 1 Data Organization
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
6
Fig: 2 (a): A linked list of n elements
Fig: 2 (b) : A linked list of weekdays
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 Each node of the linked list has minimum two elements :
The data member(s) being stored in the list
A pointer or link to the next element in the list
 The last node in the list contains a NULL (or -1) pointer to
indicate that it is the end or tail of the list
7
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 The last node in the list contains a NULL (or -1) pointer to indicate
that it is the end or tail of the list
 Provides static allocation, which means space allocation is done
by compiler once cannot be changed during execution and size has
to be known in advance.
 As individual objects are stored at fixed distance apart, we can access
any element randomly.
 Insertion and deletion of objects in between the list requires a lot of
data movement.
 Space inefficient for large objects and large quantity with often
insertions and deletions
 Element need not know/store keep address of its successive element.
8
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
 Element can be placed anywhere in the memory
 Dynamic allocation (size need not be known in advance) i.e. space
allocation as per need can be done during execution.
 As objects are not placed at fixed distance apart, random access to
elements is not possible.
 Insertion and deletion of objects do not require any data shifting.
 Space efficient for large objects and large quantity with often
insertions and deletions
 Each element in general is a collection of data and a link. At least one
link field is must.
 Every element keeps address of its successor element in a link field.
9
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
10
 Some more operations, which are based on above basic
operations are:
 Searching a node
 Updating node.
 Printing the node or list.
 Counting length of the list.
 Reverse the list.
 Sort the list using pointer manipulation.
 Concatenate two lists.
 Merge two-sorted list into third sorted list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
11
 Data Structure of Node
 Insertion of a Node
 Linked List Traversal
Non-Recursive Method
Recursive Traversal Method
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
12
 Structure of Node
 Doubly linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
13
 A linked list in which every node has one link field, to
provide information about where the next node of list is,
is called as singly linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
14
 In doubly linked list, each node has two link fields to
store information about who is the next and also about
who is ahead of the node
 Hence each node has knowledge of its successor and
also its predecessor.
 In doubly linked list, from every node the list can be
traversed in both the directions.
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
15
The other classification of linked lists is,
 Linear linked list
 Circular linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
16
 The linked list that we have seen so for are often known
as linear linked lists.
 All elements of such a linked list can be accessed by first
setting up a pointer pointing to the first node of the list
and then traversing the entire list.
Linear linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
17
 For example, consider a singly linked list.
 Given a pointer A to a node in a linear list, we cannot reach
any of the nodes that precede the node to which A is pointing.
 This disadvantage can be overcome by making a small
change. This change is without any additional data structure.
 The link field of last node is set to NULL in linear list to mark
end of list. This link field of last node can be set to point first
node rather than NULL. Such a linked list is called a circular
linked list.
Although a linear linked list is a useful and popular
data structure, it has some shortcomings.
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
18
Circular linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
19
Doubly Linked List
We can use doubly linked lists in which each node contain two links,
one to its predecessor and other to its successor
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
20
Polynomial Manipulations
A node will have 3 fields, which represent the
coefficient and exponent of a term and a pointer to
the next term
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
21
 For instance, the polynomial, say A = 6x7 + 3x5 + 4x3 +
12 would be stored as :
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
22
Operations on Polynomials
Polynomial evaluation
Polynomial addition
Multiplication of two polynomials
Representation of sparse matrix using
linked list
Linked list implementation of the stack
Generalized linked list
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
23
 Overflow : Sometimes new data node is to be
inserted into data structure but there is no available
space i.e. free-pool is empty. This situation is called
overflow
 Underflow : This refers to situation where
programmer wants to delete a node from empty list
 For good memory utilization, operating system
periodically collects all the free blocks and inserts into
free-pool
 Any technique that does this collection is called garbage
collection
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
24
 There are two implementation of linked linear list; array and pointers
 There is a need is of such a data structure which can dynamically shrink and
grow
 Hence the popular implementation us using pointers and dynamic memory
management
 Singly linked lists are useful data structures, especially if you need to
automatically allocate and de-allocate space in a list
 The basic operation are create list, transverse the list, insert and delete a
node
 There are two variation of linked list singly and doubly linked list. Both
linked list can be circular lists
 The linked could be with or without head node. Head node is used to store
some information about the list, so that it can be accessed without
traversing the same
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
25
 In doubly linked list, each node has two link fields to store information
about who is the next and also about who is ahead of the node
 Hence each node has knowledge of its successor and also its
predecessor.
 In doubly linked list, from every node the list can be traversed in both the
directions.
 Information could be like total number of nodes in the list and similarly any
other Linked list is the most popular data structure used. It has many
application such as process queue, print queue, garbage collection etc
Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil
26
End
of
Chapter 6 …!

More Related Content

What's hot (20)

PPTX
Sparse matrix and its representation data structure
Vardhil Patel
 
PDF
Stack
Zaid Shabbir
 
PPTX
Terminology of tree
RacksaviR
 
PPTX
Knuth morris pratt string matching algo
sabiya sabiya
 
PPTX
Dynamic Programming - Matrix Chain Multiplication
Pecha Inc.
 
PPTX
Tree in data structure
ghhgj jhgh
 
PPT
1.5 binary search tree
Krish_ver2
 
PPTX
Rabin karp string matching algorithm
Gajanand Sharma
 
PPTX
Python for Data Science with Anaconda
Travis Oliphant
 
PPT
Singly link list
Rojin Khadka
 
PPTX
Linked list
Md. Afif Al Mamun
 
PPTX
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
PDF
Binary search tree operations
Kamran Zafar
 
PDF
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
PPTX
Trees
Burhan Ahmed
 
PDF
Red black tree
Dr Sandeep Kumar Poonia
 
PDF
Expression trees
Salman Vadsarya
 
PPTX
Design and Analysis of Algorithms
Arvind Krishnaa
 
PDF
sparse matrix in data structure
MAHALAKSHMI P
 
PPTX
Linklist
SHEETAL WAGHMARE
 
Sparse matrix and its representation data structure
Vardhil Patel
 
Terminology of tree
RacksaviR
 
Knuth morris pratt string matching algo
sabiya sabiya
 
Dynamic Programming - Matrix Chain Multiplication
Pecha Inc.
 
Tree in data structure
ghhgj jhgh
 
1.5 binary search tree
Krish_ver2
 
Rabin karp string matching algorithm
Gajanand Sharma
 
Python for Data Science with Anaconda
Travis Oliphant
 
Singly link list
Rojin Khadka
 
Linked list
Md. Afif Al Mamun
 
Stacks IN DATA STRUCTURES
Sowmya Jyothi
 
Binary search tree operations
Kamran Zafar
 
Bca data structures linked list mrs.sowmya jyothi
Sowmya Jyothi
 
Red black tree
Dr Sandeep Kumar Poonia
 
Expression trees
Salman Vadsarya
 
Design and Analysis of Algorithms
Arvind Krishnaa
 
sparse matrix in data structure
MAHALAKSHMI P
 

Viewers also liked (19)

PPTX
Double linked list
raviahuja11
 
PPTX
7 Myths of AI
CrowdFlower
 
PDF
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
PPT
Linked list
Trupti Agrawal
 
PPT
358 33 powerpoint-slides_8-linked-lists_chapter-8
sumitbardhan
 
PPTX
Array implementation and linked list as datat structure
Tushar Aneyrao
 
PPT
linked list
Narendra Chauhan
 
PPTX
Linked list
akshat360
 
PPTX
Data structure using c module 1
smruti sarangi
 
PDF
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
PPTX
Trees data structure
Sumit Gupta
 
PPTX
Doubly linked list
Fahd Allebdi
 
PPTX
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
John C. Havens
 
PPTX
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Lovelyn Rose
 
PDF
Cyber Crime
Abhishek L.R
 
PPTX
Binary Search Tree
Abhishek L.R
 
PPTX
Open Legal Data Workshop at Stanford
Harry Surden
 
PPTX
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden
 
PPTX
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
Carol Smith
 
Double linked list
raviahuja11
 
7 Myths of AI
CrowdFlower
 
Searching and Sorting Techniques in Data Structure
Balwant Gorad
 
Linked list
Trupti Agrawal
 
358 33 powerpoint-slides_8-linked-lists_chapter-8
sumitbardhan
 
Array implementation and linked list as datat structure
Tushar Aneyrao
 
linked list
Narendra Chauhan
 
Linked list
akshat360
 
Data structure using c module 1
smruti sarangi
 
Linked List, Types of Linked LIst, Various Operations, Applications of Linked...
Balwant Gorad
 
Trees data structure
Sumit Gupta
 
Doubly linked list
Fahd Allebdi
 
Individual-In-The-Loop (for Ethically Aligned Artificial Intelligence)
John C. Havens
 
Insertion and Deletion in Binary Search Trees (using Arrays and Linked Lists)
Lovelyn Rose
 
Cyber Crime
Abhishek L.R
 
Binary Search Tree
Abhishek L.R
 
Open Legal Data Workshop at Stanford
Harry Surden
 
Harry Surden - Artificial Intelligence and Law Overview
Harry Surden
 
AI and Machine Learning Demystified by Carol Smith at Midwest UX 2017
Carol Smith
 
Ad

Similar to 6. Linked list - Data Structures using C++ by Varsha Patil (20)

PPTX
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PDF
Linked List Data Structures .
Ashutosh Satapathy
 
PPTX
DSA-Linked-List-.. learning process.pptx
ArgeeOnaler
 
PPTX
7. Tree - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
15. STL - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
DOC
DATA STRUCTURES - SHORT NOTES
suthi
 
PPTX
10. Search Tree - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
AAT PPT format - oRGINAL.pptx
YVinodKumar1
 
PDF
Static arrays are structures whose size is fixed at compile time and.pdf
anjanacottonmills
 
PPTX
DS_Ch-2_Link-List_Midterm linear data structure.pptx
kanpariyanilam
 
PPTX
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
PPTX
Which data structure is it? What are the various data structure kinds and wha...
Tutort Academy
 
PPTX
5. Queue - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
Linked list in Data Structure and Algorithm
KristinaBorooah
 
PDF
Link list
zzzubair
 
PPTX
csc211_lecture_21.pptx
ASADAHMAD811380
 
PPT
Lecture 2b lists
Victor Palmar
 
PDF
Data Structure the Basic Structure for Programming
paperpublications3
 
PPT
Linked List
CHANDAN KUMAR
 
9. Searching & Sorting - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Linked List Data Structures .
Ashutosh Satapathy
 
DSA-Linked-List-.. learning process.pptx
ArgeeOnaler
 
7. Tree - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
15. STL - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
13. Indexing MTrees - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
DATA STRUCTURES - SHORT NOTES
suthi
 
10. Search Tree - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
AAT PPT format - oRGINAL.pptx
YVinodKumar1
 
Static arrays are structures whose size is fixed at compile time and.pdf
anjanacottonmills
 
DS_Ch-2_Link-List_Midterm linear data structure.pptx
kanpariyanilam
 
DSL Unit 4 (Linked list) (PPT)SE3rd sem sppu.pptx
vaibhavkore8
 
Which data structure is it? What are the various data structure kinds and wha...
Tutort Academy
 
5. Queue - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Linked list in Data Structure and Algorithm
KristinaBorooah
 
Link list
zzzubair
 
csc211_lecture_21.pptx
ASADAHMAD811380
 
Lecture 2b lists
Victor Palmar
 
Data Structure the Basic Structure for Programming
paperpublications3
 
Linked List
CHANDAN KUMAR
 
Ad

More from widespreadpromotion (10)

PDF
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
widespreadpromotion
 
PPTX
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
14. Files - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
12. Heaps - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
11. Hashing - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
8. Graph - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
4. Recursion - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
3. Stack - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
PPTX
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
widespreadpromotion
 
PPTX
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
Discrete Mathematics S. Lipschutz, M. Lipson And V. H. Patil
widespreadpromotion
 
16. Algo analysis & Design - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
14. Files - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
12. Heaps - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
11. Hashing - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
8. Graph - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
4. Recursion - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
3. Stack - Data Structures using C++ by Varsha Patil
widespreadpromotion
 
2. Linear Data Structure Using Arrays - Data Structures using C++ by Varsha P...
widespreadpromotion
 
1. Fundamental Concept - Data Structures using C++ by Varsha Patil
widespreadpromotion
 

Recently uploaded (20)

PPTX
apidays Helsinki & North 2025 - API access control strategies beyond JWT bear...
apidays
 
PPTX
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
PDF
OPPOTUS - Malaysias on Malaysia 1Q2025.pdf
Oppotus
 
PDF
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
PDF
Research Methodology Overview Introduction
ayeshagul29594
 
PDF
Data Retrieval and Preparation Business Analytics.pdf
kayserrakib80
 
PPTX
apidays Singapore 2025 - Generative AI Landscape Building a Modern Data Strat...
apidays
 
PPT
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
PDF
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
PDF
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
PPTX
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
PDF
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
PPTX
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
PPTX
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
PPTX
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
PDF
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
PDF
Using AI/ML for Space Biology Research
VICTOR MAESTRE RAMIREZ
 
PPTX
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
PPTX
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
PDF
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 
apidays Helsinki & North 2025 - API access control strategies beyond JWT bear...
apidays
 
apidays Singapore 2025 - Designing for Change, Julie Schiller (Google)
apidays
 
OPPOTUS - Malaysias on Malaysia 1Q2025.pdf
Oppotus
 
apidays Helsinki & North 2025 - APIs in the healthcare sector: hospitals inte...
apidays
 
Research Methodology Overview Introduction
ayeshagul29594
 
Data Retrieval and Preparation Business Analytics.pdf
kayserrakib80
 
apidays Singapore 2025 - Generative AI Landscape Building a Modern Data Strat...
apidays
 
tuberculosiship-2106031cyyfuftufufufivifviviv
AkshaiRam
 
Development and validation of the Japanese version of the Organizational Matt...
Yoga Tokuyoshi
 
JavaScript - Good or Bad? Tips for Google Tag Manager
📊 Markus Baersch
 
Module-5-Measures-of-Central-Tendency-Grouped-Data-1.pptx
lacsonjhoma0407
 
The European Business Wallet: Why It Matters and How It Powers the EUDI Ecosy...
Lal Chandran
 
apidays Singapore 2025 - The Quest for the Greenest LLM , Jean Philippe Ehre...
apidays
 
Exploring Multilingual Embeddings for Italian Semantic Search: A Pretrained a...
Sease
 
apidays Helsinki & North 2025 - From Chaos to Clarity: Designing (AI-Ready) A...
apidays
 
apidays Singapore 2025 - Surviving an interconnected world with API governanc...
apidays
 
Using AI/ML for Space Biology Research
VICTOR MAESTRE RAMIREZ
 
apidays Helsinki & North 2025 - APIs at Scale: Designing for Alignment, Trust...
apidays
 
apidays Singapore 2025 - From Data to Insights: Building AI-Powered Data APIs...
apidays
 
apidays Helsinki & North 2025 - API-Powered Journeys: Mobility in an API-Driv...
apidays
 

6. Linked list - Data Structures using C++ by Varsha Patil

  • 1. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 1
  • 2. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  Recognize need of a Data Structure, which Dynamically can Shrink and Grow  Realization of Linked List as Dynamic Data StructureTo understand the well-defined, clear, and simple approach of program design  Utilize Flexibility of the same Easily and EffectivelyTo understand sequential organization of data  Learn Variations of Linked List and Use them for Appropriate Applications 2
  • 3. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 3  The linked list is a very effective and efficient dynamic data structure  Data items can be stored anywhere in memory in a scattered manner  To maintain the specific sequence of these data items we need to maintain link(s) with successor (and/ or predecessor)  It is called as a linked list
  • 4. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  A linked list is an ordered collection of data in which each element contains minimum two values, data and link(s) to its successor (and/ or predecessor)  The list with one link field using which every element is associated to either its predecessor or successor is called as singly linked list  In a linked list, before adding any element to the list, memory space for that node must be allocated  A link is kept with each item to the next item in the list 4
  • 5. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 5 Fig: 1 Data Organization
  • 6. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 6 Fig: 2 (a): A linked list of n elements Fig: 2 (b) : A linked list of weekdays
  • 7. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  Each node of the linked list has minimum two elements : The data member(s) being stored in the list A pointer or link to the next element in the list  The last node in the list contains a NULL (or -1) pointer to indicate that it is the end or tail of the list 7
  • 8. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  The last node in the list contains a NULL (or -1) pointer to indicate that it is the end or tail of the list  Provides static allocation, which means space allocation is done by compiler once cannot be changed during execution and size has to be known in advance.  As individual objects are stored at fixed distance apart, we can access any element randomly.  Insertion and deletion of objects in between the list requires a lot of data movement.  Space inefficient for large objects and large quantity with often insertions and deletions  Element need not know/store keep address of its successive element. 8
  • 9. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil  Element can be placed anywhere in the memory  Dynamic allocation (size need not be known in advance) i.e. space allocation as per need can be done during execution.  As objects are not placed at fixed distance apart, random access to elements is not possible.  Insertion and deletion of objects do not require any data shifting.  Space efficient for large objects and large quantity with often insertions and deletions  Each element in general is a collection of data and a link. At least one link field is must.  Every element keeps address of its successor element in a link field. 9
  • 10. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 10  Some more operations, which are based on above basic operations are:  Searching a node  Updating node.  Printing the node or list.  Counting length of the list.  Reverse the list.  Sort the list using pointer manipulation.  Concatenate two lists.  Merge two-sorted list into third sorted list
  • 11. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 11  Data Structure of Node  Insertion of a Node  Linked List Traversal Non-Recursive Method Recursive Traversal Method
  • 12. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 12  Structure of Node  Doubly linked list
  • 13. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 13  A linked list in which every node has one link field, to provide information about where the next node of list is, is called as singly linked list
  • 14. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 14  In doubly linked list, each node has two link fields to store information about who is the next and also about who is ahead of the node  Hence each node has knowledge of its successor and also its predecessor.  In doubly linked list, from every node the list can be traversed in both the directions.
  • 15. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 15 The other classification of linked lists is,  Linear linked list  Circular linked list
  • 16. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 16  The linked list that we have seen so for are often known as linear linked lists.  All elements of such a linked list can be accessed by first setting up a pointer pointing to the first node of the list and then traversing the entire list. Linear linked list
  • 17. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 17  For example, consider a singly linked list.  Given a pointer A to a node in a linear list, we cannot reach any of the nodes that precede the node to which A is pointing.  This disadvantage can be overcome by making a small change. This change is without any additional data structure.  The link field of last node is set to NULL in linear list to mark end of list. This link field of last node can be set to point first node rather than NULL. Such a linked list is called a circular linked list. Although a linear linked list is a useful and popular data structure, it has some shortcomings.
  • 18. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 18 Circular linked list
  • 19. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 19 Doubly Linked List We can use doubly linked lists in which each node contain two links, one to its predecessor and other to its successor
  • 20. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 20 Polynomial Manipulations A node will have 3 fields, which represent the coefficient and exponent of a term and a pointer to the next term
  • 21. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 21  For instance, the polynomial, say A = 6x7 + 3x5 + 4x3 + 12 would be stored as :
  • 22. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 22 Operations on Polynomials Polynomial evaluation Polynomial addition Multiplication of two polynomials Representation of sparse matrix using linked list Linked list implementation of the stack Generalized linked list
  • 23. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 23  Overflow : Sometimes new data node is to be inserted into data structure but there is no available space i.e. free-pool is empty. This situation is called overflow  Underflow : This refers to situation where programmer wants to delete a node from empty list  For good memory utilization, operating system periodically collects all the free blocks and inserts into free-pool  Any technique that does this collection is called garbage collection
  • 24. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 24  There are two implementation of linked linear list; array and pointers  There is a need is of such a data structure which can dynamically shrink and grow  Hence the popular implementation us using pointers and dynamic memory management  Singly linked lists are useful data structures, especially if you need to automatically allocate and de-allocate space in a list  The basic operation are create list, transverse the list, insert and delete a node  There are two variation of linked list singly and doubly linked list. Both linked list can be circular lists  The linked could be with or without head node. Head node is used to store some information about the list, so that it can be accessed without traversing the same
  • 25. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 25  In doubly linked list, each node has two link fields to store information about who is the next and also about who is ahead of the node  Hence each node has knowledge of its successor and also its predecessor.  In doubly linked list, from every node the list can be traversed in both the directions.  Information could be like total number of nodes in the list and similarly any other Linked list is the most popular data structure used. It has many application such as process queue, print queue, garbage collection etc
  • 26. Oxford University Press © 2012Data Structures Using C++ by Dr Varsha Patil 26 End of Chapter 6 …!