SlideShare a Scribd company logo
 A linked list is a linear data structure.
 Nodes make up linked lists.
 Nodes are structures made up of data and
a pointer to another node.
 Usually the pointer is called next.
Arrays Vs Linked Lists
Arrays Linked list
Fixed size: Resizing is expensive Dynamic size
Insertions and Deletions are inefficient:
Elements are usually shifted
Insertions and Deletions are efficient: No
shifting
Random access i.e., efficient indexing No random access
 Not suitable for operations requiring
accessing elements by index such as sorting
No memory waste if the array is full or almost
full; otherwise may result in much memory
waste.
Since memory is allocated dynamically(acc. to
our need) there is no waste of memory.
Sequential access is faster [Reason: Elements in
contiguous memory locations]
Sequential access is slow [Reason: Elements not
in contiguous memory locations]
Singly Linked List
 Each node has only one link part
 Each link part contains the address of the next node in the list
 Link part of the last node contains NULL value which signifies the end of
the node
Schematic representation
 Here is a singly-linked list (SLL):
a b c d
myList
• Each node contains a value(data) and a
pointer to the next node in the list
• myList is the header pointer which points
at the first node in the list
Basic Operations on a list
• Creating a List
• Inserting an element in a list
• Deleting an element from a list
• Searching a list
• Reversing a list
Inserting the node in a SLL
There are 3 cases here:-
Insertion at the beginning
Insertion at the end
Insertion after a particular node
Insertion at the beginning
There are two steps to be followed:-
a) Make the next pointer of the node point towards the first node of the
list
b) Make the start pointer point towards this new node
 If the list is empty simply make the start pointer point towards the new
node;
linked list using c
linked list using c
Inserting at the end
Here we simply need to make the next pointer
of the last node point to the new node
Inserting after an element
Here we again need to do 2 steps :-
 Make the next pointer of the node to be
inserted point to the next node of the node
after which you want to insert the node
 Make the next pointer of the node after which
the node is to be inserted, point to the node to
be inserted
Inserting after an element at end
algorithm :-
 STEP-1: new=getnode
 STEP-2: temp=first
 STEP-3: while(temp->next)!=NULL
 STEP-4: temp=temp->next
 STEP-5: end while
 STEP-6: temp->next=new
 STEP-7: temp=new
 STEP-8: stop
linked list using c
Deleting a node in SLL
Here also we have three cases:-
 Deleting the first node
 Deleting the last node
 Deleting the intermediate node
Deleting the first node
Here we apply 2 steps:-
 Making the start pointer point towards the 2nd node
 Deleting the first node using delete keyword
threetwoone
start
Deleting the last node
Here we apply 2 steps:-
 Making the second last node’s next pointer point
to NULL
 Deleting the last node via delete keyword
node3node2node1
start
Deleting a particular node
Here we make the next pointer of the node previous to the node being
deleted ,point to the successor node of the node to be deleted and then
delete the node using delete keyword
node1 node2 node3
To be deleted
Searching a SLL
 Searching involves finding the required element in the list
 We can use various techniques of searching like linear search or binary
search where binary search is more efficient in case of Arrays
 But in case of linked list since random access is not available it would
become complex to do binary search in it
 We can perform simple linear search traversal
Reversing a linked list
• We can reverse a linked list by reversing the
direction of the links between 2 nodes
 We make use of 3 structure pointers say p,q,r
 At any instant q will point to the node next to p and r will point to the
node next to q
NULLHead P q r
NULL
• For next iteration p=q and q=r
• At the end we will change head to the last node
p q
Ad

More Related Content

What's hot (20)

Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL
 
Linked List
Linked ListLinked List
Linked List
RaaviKapoor
 
Unit 2 linked list
Unit 2   linked listUnit 2   linked list
Unit 2 linked list
DrkhanchanaR
 
datastructure concepts ppt-190327174340.pptx
datastructure concepts ppt-190327174340.pptxdatastructure concepts ppt-190327174340.pptx
datastructure concepts ppt-190327174340.pptx
JeevaMCSEKIOT
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
Rameesha Sadaqat
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
sajinis3
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
Prateek Parimal
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
Complexity analysis in Algorithms
Complexity analysis in AlgorithmsComplexity analysis in Algorithms
Complexity analysis in Algorithms
Daffodil International University
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
Megha yadav
 
Linked list
Linked listLinked list
Linked list
eShikshak
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Unit 4 plsql
Unit 4  plsqlUnit 4  plsql
Unit 4 plsql
DrkhanchanaR
 
Queue ppt
Queue pptQueue ppt
Queue ppt
SouravKumar328
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
PTCL
 
Unit 2 linked list
Unit 2   linked listUnit 2   linked list
Unit 2 linked list
DrkhanchanaR
 
datastructure concepts ppt-190327174340.pptx
datastructure concepts ppt-190327174340.pptxdatastructure concepts ppt-190327174340.pptx
datastructure concepts ppt-190327174340.pptx
JeevaMCSEKIOT
 
Ppt on Linked list,stack,queue
Ppt on Linked list,stack,queuePpt on Linked list,stack,queue
Ppt on Linked list,stack,queue
Srajan Shukla
 
Priority Queue in Data Structure
Priority Queue in Data StructurePriority Queue in Data Structure
Priority Queue in Data Structure
Meghaj Mallick
 
Data structure & its types
Data structure & its typesData structure & its types
Data structure & its types
Rameesha Sadaqat
 
Doubly Linked List
Doubly Linked ListDoubly Linked List
Doubly Linked List
Ninad Mankar
 
Circular linked list
Circular linked list Circular linked list
Circular linked list
sajinis3
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
madhav bansal
 
Integrity Constraints
Integrity ConstraintsIntegrity Constraints
Integrity Constraints
Megha yadav
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
imtiazalijoono
 
Data Structures - Lecture 9 [Stack & Queue using Linked List]
 Data Structures - Lecture 9 [Stack & Queue using Linked List] Data Structures - Lecture 9 [Stack & Queue using Linked List]
Data Structures - Lecture 9 [Stack & Queue using Linked List]
Muhammad Hammad Waseem
 

Viewers also liked (17)

Data structures, bcs 3 c- linked list
Data structures, bcs 3 c- linked listData structures, bcs 3 c- linked list
Data structures, bcs 3 c- linked list
Haqnawaz Ch
 
Doublylinklist
DoublylinklistDoublylinklist
Doublylinklist
ritu1806
 
Caja entradas y salidas
Caja entradas y salidasCaja entradas y salidas
Caja entradas y salidas
juan martinez
 
презентация группы "Сказка"
презентация группы "Сказка"презентация группы "Сказка"
презентация группы "Сказка"
Елена Семакина
 
Uso Seguro de la Red
Uso Seguro de la RedUso Seguro de la Red
Uso Seguro de la Red
Antonio Torrecilla Martínez
 
21 Trends For Nurse Practitioners In 2016
21 Trends For Nurse Practitioners In 201621 Trends For Nurse Practitioners In 2016
21 Trends For Nurse Practitioners In 2016
Harshada Sabale
 
презентация 8гр "Дружная семейка"
презентация 8гр "Дружная семейка"презентация 8гр "Дружная семейка"
презентация 8гр "Дружная семейка"
Елена Семакина
 
группа 10 почемучки
группа 10 почемучкигруппа 10 почемучки
группа 10 почемучки
Елена Семакина
 
цветик семицветик
цветик семицветикцветик семицветик
цветик семицветик
Елена Семакина
 
цветик семицветик
цветик семицветикцветик семицветик
цветик семицветик
Елена Семакина
 
New Rules Strategies 2015
New Rules Strategies 2015New Rules Strategies 2015
New Rules Strategies 2015
Greg Winokur
 
SocialMedia_Vogts
SocialMedia_VogtsSocialMedia_Vogts
SocialMedia_Vogts
Abigail Vogts
 
группа 10 почемучки
группа 10 почемучкигруппа 10 почемучки
группа 10 почемучки
Елена Семакина
 
External Resume 16Jan2016
External Resume 16Jan2016External Resume 16Jan2016
External Resume 16Jan2016
Barbara Williams
 
Trabajo sobre internet
Trabajo sobre internetTrabajo sobre internet
Trabajo sobre internet
maaariafdez
 
группа 10 почемучки
группа 10 почемучкигруппа 10 почемучки
группа 10 почемучки
Елена Семакина
 
группа пчёлка 7гр
группа пчёлка 7гргруппа пчёлка 7гр
группа пчёлка 7гр
Елена Семакина
 
Ad

Similar to linked list using c (20)

data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power p
MeghaKulkarni27
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
Linked list (1).pptx
Linked list (1).pptxLinked list (1).pptx
Linked list (1).pptx
rajveersingh643731
 
Linkedlist
LinkedlistLinkedlist
Linkedlist
Taslima Yasmin Tarin
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data Structure
Meghaj Mallick
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Linked list
Linked listLinked list
Linked list
Muhammad Qasim
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
Linked List, basics , types , operations
Linked List, basics , types , operationsLinked List, basics , types , operations
Linked List, basics , types , operations
ankita946617
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
Link_List.pptx
Link_List.pptxLink_List.pptx
Link_List.pptx
sandeep54552
 
linked list_MODULE 3.pptx ppt on the linked list
linked list_MODULE 3.pptx ppt on the linked listlinked list_MODULE 3.pptx ppt on the linked list
linked list_MODULE 3.pptx ppt on the linked list
AnuragKumar682871
 
Linkedlists
LinkedlistsLinkedlists
Linkedlists
Rajendran
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
NirmalPandey23
 
Linked List Representation of a Linked List.pptx
Linked List Representation of a Linked List.pptxLinked List Representation of a Linked List.pptx
Linked List Representation of a Linked List.pptx
AAUsH2
 
ANOITO2341988888888888888888888885555.ppt
ANOITO2341988888888888888888888885555.pptANOITO2341988888888888888888888885555.ppt
ANOITO2341988888888888888888888885555.ppt
robertobula2
 
Link list using array in Data structure amd algorithms
Link list using array in Data structure amd algorithmsLink list using array in Data structure amd algorithms
Link list using array in Data structure amd algorithms
pwstudent403
 
Linked list, Singly link list and its operations
Linked list, Singly link list and its operationsLinked list, Singly link list and its operations
Linked list, Singly link list and its operations
BackiyalakshmiVenkat
 
Data Structures Introduction & Linear DS
Data Structures Introduction & Linear DSData Structures Introduction & Linear DS
Data Structures Introduction & Linear DS
sailaja156145
 
data structures and applications power p
data structures and applications power pdata structures and applications power p
data structures and applications power p
MeghaKulkarni27
 
ds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdfds-lecture-4-171012041008 (1).pdf
ds-lecture-4-171012041008 (1).pdf
KamranAli649587
 
Linked List in Data Structure
Linked List in Data StructureLinked List in Data Structure
Linked List in Data Structure
Meghaj Mallick
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
1.3 Linked List.pptx
1.3 Linked List.pptx1.3 Linked List.pptx
1.3 Linked List.pptx
ssuserd2f031
 
Datastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptxDatastucture-Unit 4-Linked List Presentation.pptx
Datastucture-Unit 4-Linked List Presentation.pptx
kaleeswaric3
 
Linked List, basics , types , operations
Linked List, basics , types , operationsLinked List, basics , types , operations
Linked List, basics , types , operations
ankita946617
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
linked list_MODULE 3.pptx ppt on the linked list
linked list_MODULE 3.pptx ppt on the linked listlinked list_MODULE 3.pptx ppt on the linked list
linked list_MODULE 3.pptx ppt on the linked list
AnuragKumar682871
 
Linked List Representation of a Linked List.pptx
Linked List Representation of a Linked List.pptxLinked List Representation of a Linked List.pptx
Linked List Representation of a Linked List.pptx
AAUsH2
 
ANOITO2341988888888888888888888885555.ppt
ANOITO2341988888888888888888888885555.pptANOITO2341988888888888888888888885555.ppt
ANOITO2341988888888888888888888885555.ppt
robertobula2
 
Link list using array in Data structure amd algorithms
Link list using array in Data structure amd algorithmsLink list using array in Data structure amd algorithms
Link list using array in Data structure amd algorithms
pwstudent403
 
Linked list, Singly link list and its operations
Linked list, Singly link list and its operationsLinked list, Singly link list and its operations
Linked list, Singly link list and its operations
BackiyalakshmiVenkat
 
Data Structures Introduction & Linear DS
Data Structures Introduction & Linear DSData Structures Introduction & Linear DS
Data Structures Introduction & Linear DS
sailaja156145
 
Ad

Recently uploaded (20)

U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdfIPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
IPL QUIZ | THE QUIZ CLUB OF PSGCAS | 2025.pdf
Quiz Club of PSG College of Arts & Science
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
How to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 PurchaseHow to Manage Amounts in Local Currency in Odoo 18 Purchase
How to Manage Amounts in Local Currency in Odoo 18 Purchase
Celine George
 
Pope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptxPope Leo XIV, the first Pope from North America.pptx
Pope Leo XIV, the first Pope from North America.pptx
Martin M Flynn
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
libbys peer assesment.docx..............
libbys peer assesment.docx..............libbys peer assesment.docx..............
libbys peer assesment.docx..............
19lburrell
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
How to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo SlidesHow to Add Button in Chatter in Odoo 18 - Odoo Slides
How to Add Button in Chatter in Odoo 18 - Odoo Slides
Celine George
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
Module_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptxModule_2_Types_and_Approaches_of_Research (2).pptx
Module_2_Types_and_Approaches_of_Research (2).pptx
drroxannekemp
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx2025 The Senior Landscape and SET plan preparations.pptx
2025 The Senior Landscape and SET plan preparations.pptx
mansk2
 
How to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 WebsiteHow to Configure Extra Steps During Checkout in Odoo 18 Website
How to Configure Extra Steps During Checkout in Odoo 18 Website
Celine George
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
The role of wall art in interior designing
The role of wall art in interior designingThe role of wall art in interior designing
The role of wall art in interior designing
meghaark2110
 

linked list using c

  • 1.  A linked list is a linear data structure.  Nodes make up linked lists.  Nodes are structures made up of data and a pointer to another node.  Usually the pointer is called next.
  • 2. Arrays Vs Linked Lists Arrays Linked list Fixed size: Resizing is expensive Dynamic size Insertions and Deletions are inefficient: Elements are usually shifted Insertions and Deletions are efficient: No shifting Random access i.e., efficient indexing No random access  Not suitable for operations requiring accessing elements by index such as sorting No memory waste if the array is full or almost full; otherwise may result in much memory waste. Since memory is allocated dynamically(acc. to our need) there is no waste of memory. Sequential access is faster [Reason: Elements in contiguous memory locations] Sequential access is slow [Reason: Elements not in contiguous memory locations]
  • 3. Singly Linked List  Each node has only one link part  Each link part contains the address of the next node in the list  Link part of the last node contains NULL value which signifies the end of the node
  • 4. Schematic representation  Here is a singly-linked list (SLL): a b c d myList • Each node contains a value(data) and a pointer to the next node in the list • myList is the header pointer which points at the first node in the list
  • 5. Basic Operations on a list • Creating a List • Inserting an element in a list • Deleting an element from a list • Searching a list • Reversing a list
  • 6. Inserting the node in a SLL There are 3 cases here:- Insertion at the beginning Insertion at the end Insertion after a particular node
  • 7. Insertion at the beginning There are two steps to be followed:- a) Make the next pointer of the node point towards the first node of the list b) Make the start pointer point towards this new node  If the list is empty simply make the start pointer point towards the new node;
  • 10. Inserting at the end Here we simply need to make the next pointer of the last node point to the new node
  • 11. Inserting after an element Here we again need to do 2 steps :-  Make the next pointer of the node to be inserted point to the next node of the node after which you want to insert the node  Make the next pointer of the node after which the node is to be inserted, point to the node to be inserted
  • 12. Inserting after an element at end algorithm :-  STEP-1: new=getnode  STEP-2: temp=first  STEP-3: while(temp->next)!=NULL  STEP-4: temp=temp->next  STEP-5: end while  STEP-6: temp->next=new  STEP-7: temp=new  STEP-8: stop
  • 14. Deleting a node in SLL Here also we have three cases:-  Deleting the first node  Deleting the last node  Deleting the intermediate node
  • 15. Deleting the first node Here we apply 2 steps:-  Making the start pointer point towards the 2nd node  Deleting the first node using delete keyword threetwoone start
  • 16. Deleting the last node Here we apply 2 steps:-  Making the second last node’s next pointer point to NULL  Deleting the last node via delete keyword node3node2node1 start
  • 17. Deleting a particular node Here we make the next pointer of the node previous to the node being deleted ,point to the successor node of the node to be deleted and then delete the node using delete keyword node1 node2 node3 To be deleted
  • 18. Searching a SLL  Searching involves finding the required element in the list  We can use various techniques of searching like linear search or binary search where binary search is more efficient in case of Arrays  But in case of linked list since random access is not available it would become complex to do binary search in it  We can perform simple linear search traversal
  • 19. Reversing a linked list • We can reverse a linked list by reversing the direction of the links between 2 nodes
  • 20.  We make use of 3 structure pointers say p,q,r  At any instant q will point to the node next to p and r will point to the node next to q NULLHead P q r NULL • For next iteration p=q and q=r • At the end we will change head to the last node p q
  翻译: