SlideShare a Scribd company logo
LINKED LIST OPERATIONS
By,
Shashank Shetty
Assistant Professor,
Department of ISE
NMAMIT, Nitte
Shashankshetty@nitte.edu.in
Inserting a node into a SLL
There are many ways you might want to
insert a new node into a list:
As the new first element
As the new last element
 In the middle of the two nodes or in some
designated position.
Shashankshetty@nitte.edu.in
25
1) Insert a node at the beginning of the list
// Algorithm : Insertion (Item)
// Description : Inserts a node at the beginning of
the SLL
Step1: Start
Step 2: NewNode=getnode()
NewNode -> link = NULL
NewNode -> info = Item
Step 3: [ If the Linked list is empty, then the New
Node Created is a first node or Head Node]
if(Head==NULL)
Head=NewNode
return
End if
Step 4: [If the linked list is not empty]
NewNode -> link= Head
Head= NewNode
Free(NewNode)
Step 5: Return (Stop)
Item NULL
NewNode
Head
NULL
4 6 NULL
Head
254 6 NULLItem
Head
Shashankshetty@nitte.edu.in
2) Insert a node at the End of the list
// Algorithm : Insertion (Item)
// Description : Inserts a node at the End of
the SLL
Step1: Start
Step 2: NewNode=getnode()
NewNode -> link = NULL
NewNode -> info = Item
Step 3: [ If the Linked list is empty, then the
New Node Created is a first node or Head
Node]
if(Head==NULL)
Head=NewNode
return
End if
Step 4: [If the linked list is not empty]
Cur= Head
While (Cur-> link !=NULL)
Cur=Cur->link
end while
Step 5: Cur -> link= NewNode
Step 6: Free(NewNode)
Free (Cur)
Step 5: Return (Stop)
25
Item NULL
NewNode
Head
NULL
4 6 NULL
Head
625 item NULL4
Head
Cur Cur
Shashankshetty@nitte.edu.in
Shashankshetty@nitte.edu.in
3) Insert a node at the middle of two nodes or at
the designated position
// Algorithm : Insertion (Item, position)
// Description : Inserts a node at the middle or at the
designated position of the SLL
Step1: Start
Step 2: NewNode=getnode()
NewNode -> link = NULL
NewNode -> info = Item
Step 3: [ If the Linked list is empty, then the New Node
Created is a first node or Head Node]
if(Head==NULL)
Head=NewNode
return
End if
Step 4: [If the linked list is not empty]
Cur= Head
While (Cur!=position-1)
Cur=Cur->link
end while
Cur1=Cur->link
Step 5: Cur->link= NewNode
NewNode->link= Cur1
Step 6: Free(NewNode)
Free (Cur)
Free(Cur1)
Step 5: Return (Stop)
25
Item NULL
NewNode
Head
NULL
4 6 NULL
Head
625 item NULL4
Head
Cur Cur
1 2 3
Let Us insert
the new
node at
position 3!!!
Cur1
Shashankshetty@nitte.edu.in
Deleting a node from SLL
There are many ways you might want to
delete a new node from a list:
Delete first element
Delete last element
 From the middle of the two nodes or in some
designated position.
Shashankshetty@nitte.edu.in
25
1) Delete a node from the beginning of the list
// Algorithm : Deletion (Item)
// Description : Delete a node from the beginning of
the SLL
Step1: Start
Step 2: [If Empty List]
If (Head==NULL)
Display (“List Empty”)
Return
EndIf
Step 3: [If the linked list is not empty]
Temp=Head
Head=Head-> link
display (temp->info)
Free(Temp)
Step 4: Return (Stop)
Head
NULL
4 6 NULL
Head
25 6 NULL
Head
List
Empty
Temp
Shashankshetty@nitte.edu.in
25
2) Delete a node from the End of the list
// Algorithm : Deletion (Item)
// Description : Delete a node from the end of the
SLL
Step1: Start
Step 2: [If Empty List]
If (Head==NULL)
Display (“List Empty”)
Return
EndIf
Step 3: [If the linked list is not empty]
Temp=Head
While(temp->link!=NULL)
temp1=temp
temp=temp->link
end while
temp1->next=NULL
display (temp->info)
Free(Temp)
Step 4: Return (Stop)
Head
NULL
4 6 NULL
Head
NULL
Temp1
List
Empty
Temp TempTemp1 Temp
NULL
25
Head
4
Shashankshetty@nitte.edu.in
3) Delete a node from the Middle positionor from
specified position
// Algorithm : Deletion (Item, position)
// Description : Delete a node from the
specified position of the SLL
Step1: Start
Step 2: If(Position<=0 or position>length)
Display(“Node position doenot exist”)
EndIf
Step 3: [If Empty List]
If (Head==NULL)
Display (“List Empty”)
Return
EndIf
Step 3: [If the linked list is not empty]
Temp=Head
While(temp !=pos)
temp1=temp
temp=temp->link
end while
temp1->next=temp->next
display (temp->info)
Free(Temp)
Step 4: Return (Stop)

More Related Content

What's hot

Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
naymulhaque
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)
shah alom
 
Link list
Link listLink list
Link list
Ravi Gautam
 
Linked List
Linked ListLinked List
Linked List
Ashim Lamichhane
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
Reazul Islam
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
ManishPrajapati78
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
Estiak Khan
 
Linked list
Linked listLinked list
Linked listVONI
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
Khuram Shahzad
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
maamir farooq
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
Sumathi Kv
 
linked list
linked list linked list
linked list
Mohaimin Rahat
 
Linked lists
Linked listsLinked lists
Linked lists
SARITHA REDDY
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
Afaq Mansoor Khan
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
Abdullah Al-hazmy
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5Kumar
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
Amar Jukuntla
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
Tirthika Bandi
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
Durga Devi
 
linked list using c
linked list using clinked list using c
linked list using c
Venkat Reddy
 

What's hot (20)

Linked lists 1
Linked lists 1Linked lists 1
Linked lists 1
 
Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)Link list presentation slide(Daffodil international university)
Link list presentation slide(Daffodil international university)
 
Link list
Link listLink list
Link list
 
Linked List
Linked ListLinked List
Linked List
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
Data Structure and Algorithms Linked List
Data Structure and Algorithms Linked ListData Structure and Algorithms Linked List
Data Structure and Algorithms Linked List
 
Deletion from single way linked list and search
Deletion from single way linked list and searchDeletion from single way linked list and search
Deletion from single way linked list and search
 
Linked list
Linked listLinked list
Linked list
 
Linked lists a
Linked lists aLinked lists a
Linked lists a
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
 
Operations on linked list
Operations on linked listOperations on linked list
Operations on linked list
 
linked list
linked list linked list
linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Data Structures- Part7 linked lists
Data Structures- Part7 linked listsData Structures- Part7 linked lists
Data Structures- Part7 linked lists
 
Data structure lecture 5
Data structure lecture 5Data structure lecture 5
Data structure lecture 5
 
Singly linked list
Singly linked listSingly linked list
Singly linked list
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Unit ii(dsc++)
Unit ii(dsc++)Unit ii(dsc++)
Unit ii(dsc++)
 
linked list using c
linked list using clinked list using c
linked list using c
 

Viewers also liked

Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
J.T.A.JONES
 
Linked list
Linked listLinked list
Linked list
akshat360
 
Linked lists
Linked listsLinked lists
U2.linked list
U2.linked listU2.linked list
U2.linked list
Ssankett Negi
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
Sukhdeep Kaur
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsAakash deep Singhal
 
Linked Lists
Linked ListsLinked Lists
Linked Lists
Hafiz Umair
 
Bai toan va thuat toan
Bai toan va thuat toanBai toan va thuat toan
Bai toan va thuat toanHữu Duy Duy
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
GowriKumar Chandramouli
 
Quick sort
Quick sortQuick sort
Quick sort
Jehat Hassan
 
Quick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And AnalysisQuick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And Analysis
SNJ Chaudhary
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
irdginfo
 
Heap sort
Heap sortHeap sort
Heap sort
kaushiklv
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
Hossain Md Shakhawat
 
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPTBài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
MasterCode.vn
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
Gurukul Kangri Vishwavidyalaya - Faculty of Engineering and Technology
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
Dharita Chokshi
 

Viewers also liked (20)

Sorting & Linked Lists
Sorting & Linked ListsSorting & Linked Lists
Sorting & Linked Lists
 
Linked list
Linked listLinked list
Linked list
 
Linked lists
Linked listsLinked lists
Linked lists
 
U2.linked list
U2.linked listU2.linked list
U2.linked list
 
Ppt of operations on one way link list
Ppt of operations on one way  link listPpt of operations on one way  link list
Ppt of operations on one way link list
 
Lecture 4 data structures and algorithms
Lecture 4 data structures and algorithmsLecture 4 data structures and algorithms
Lecture 4 data structures and algorithms
 
Linked Lists
Linked ListsLinked Lists
Linked Lists
 
Bai toan va thuat toan
Bai toan va thuat toanBai toan va thuat toan
Bai toan va thuat toan
 
Quicksort
QuicksortQuicksort
Quicksort
 
Binary Search Tree
Binary Search TreeBinary Search Tree
Binary Search Tree
 
Quick sort
Quick sortQuick sort
Quick sort
 
Quick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And AnalysisQuick sort Algorithm Discussion And Analysis
Quick sort Algorithm Discussion And Analysis
 
Quicksort Presentation
Quicksort PresentationQuicksort Presentation
Quicksort Presentation
 
Heap sort
Heap sortHeap sort
Heap sort
 
Binary search tree(bst)
Binary search tree(bst)Binary search tree(bst)
Binary search tree(bst)
 
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPTBài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
Bài 5: Các thuật toán sắp xếp và tìm kiếm cơ bản - Giáo trình FPT
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
 
Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures Trees, Binary Search Tree, AVL Tree in Data Structures
Trees, Binary Search Tree, AVL Tree in Data Structures
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
 
Binary Search Tree in Data Structure
Binary Search Tree in Data StructureBinary Search Tree in Data Structure
Binary Search Tree in Data Structure
 

Similar to Linked list

Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
kalyanineve
 
Ds06 linked list- insert a node at beginning
Ds06   linked list- insert a node at beginningDs06   linked list- insert a node at beginning
Ds06 linked list- insert a node at beginning
jyoti_lakhani
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
AlliVinay1
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
Dabbal Singh Mahara
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
ISHAN194169
 
Linked list
Linked list Linked list
Linked list
Arbind Mandal
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
beshahashenafe20
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
DivyeshKumar Jagatiya
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
Mandeep Singh
 
Linked List
Linked ListLinked List
Linked List
Md gulam sarwar
 
Ds06 linked list- insert a node at end
Ds06   linked list- insert a node at endDs06   linked list- insert a node at end
Ds06 linked list- insert a node at end
jyoti_lakhani
 
Linked list
Linked listLinked list
Linked list
KalaivaniKS1
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
EmilyMengich
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
Axmedcarb
 
linked list
linked listlinked list
linked list
Ayesha Sajjad
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
nikhilcse1
 
Link list 2
Link list 2Link list 2
Link list 2
sana younas
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
kasthurimukila
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
ThenmozhiK5
 

Similar to Linked list (20)

Unit 2 linked list and queues
Unit 2   linked list and queuesUnit 2   linked list and queues
Unit 2 linked list and queues
 
Ds06 linked list- insert a node at beginning
Ds06   linked list- insert a node at beginningDs06   linked list- insert a node at beginning
Ds06 linked list- insert a node at beginning
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
linkrd_list.pdf
linkrd_list.pdflinkrd_list.pdf
linkrd_list.pdf
 
Linked list
Linked list Linked list
Linked list
 
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssssDSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
DSA chapter 4.pptxhdjaaaaaadjhsssssssssssssssssssssssssss
 
Doubly linked list (animated)
Doubly linked list (animated)Doubly linked list (animated)
Doubly linked list (animated)
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
Linked List
Linked ListLinked List
Linked List
 
Ds06 linked list- insert a node at end
Ds06   linked list- insert a node at endDs06   linked list- insert a node at end
Ds06 linked list- insert a node at end
 
Linked list
Linked listLinked list
Linked list
 
Algo>ADT list & linked list
Algo>ADT list & linked listAlgo>ADT list & linked list
Algo>ADT list & linked list
 
Linked list.docx
Linked list.docxLinked list.docx
Linked list.docx
 
Chapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdfChapter 3 Linkedlist Data Structure .pdf
Chapter 3 Linkedlist Data Structure .pdf
 
linked list
linked listlinked list
linked list
 
Linked List Presentation in data structurepptx
Linked List Presentation in data structurepptxLinked List Presentation in data structurepptx
Linked List Presentation in data structurepptx
 
Link list 2
Link list 2Link list 2
Link list 2
 
Linked list and its operations - Traversal
Linked list and its operations - TraversalLinked list and its operations - Traversal
Linked list and its operations - Traversal
 
Data Structures_Linked List
Data Structures_Linked ListData Structures_Linked List
Data Structures_Linked List
 

Recently uploaded

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
Kamal Acharya
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
MLILAB
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
Kamal Acharya
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
Osamah Alsalih
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
Kamal Acharya
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
Kamal Acharya
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
Kamal Acharya
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Teleport Manpower Consultant
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
bakpo1
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
Jayaprasanna4
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation & Control
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
gerogepatton
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
AafreenAbuthahir2
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
ssuser9bd3ba
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
AhmedHussein950959
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
Kamal Acharya
 

Recently uploaded (20)

Automobile Management System Project Report.pdf
Automobile Management System Project Report.pdfAutomobile Management System Project Report.pdf
Automobile Management System Project Report.pdf
 
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang,  ICLR 2024, MLILAB, KAIST AI.pdfJ.Yang,  ICLR 2024, MLILAB, KAIST AI.pdf
J.Yang, ICLR 2024, MLILAB, KAIST AI.pdf
 
Final project report on grocery store management system..pdf
Final project report on grocery store management system..pdfFinal project report on grocery store management system..pdf
Final project report on grocery store management system..pdf
 
MCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdfMCQ Soil mechanics questions (Soil shear strength).pdf
MCQ Soil mechanics questions (Soil shear strength).pdf
 
Courier management system project report.pdf
Courier management system project report.pdfCourier management system project report.pdf
Courier management system project report.pdf
 
Vaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdfVaccine management system project report documentation..pdf
Vaccine management system project report documentation..pdf
 
Event Management System Vb Net Project Report.pdf
Event Management System Vb Net  Project Report.pdfEvent Management System Vb Net  Project Report.pdf
Event Management System Vb Net Project Report.pdf
 
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdfTop 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
Top 10 Oil and Gas Projects in Saudi Arabia 2024.pdf
 
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
一比一原版(SFU毕业证)西蒙菲莎大学毕业证成绩单如何办理
 
ethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.pptethical hacking in wireless-hacking1.ppt
ethical hacking in wireless-hacking1.ppt
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Water Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdfWater Industry Process Automation and Control Monthly - May 2024.pdf
Water Industry Process Automation and Control Monthly - May 2024.pdf
 
Immunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary AttacksImmunizing Image Classifiers Against Localized Adversary Attacks
Immunizing Image Classifiers Against Localized Adversary Attacks
 
WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234WATER CRISIS and its solutions-pptx 1234
WATER CRISIS and its solutions-pptx 1234
 
LIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.pptLIGA(E)11111111111111111111111111111111111111111.ppt
LIGA(E)11111111111111111111111111111111111111111.ppt
 
ASME IX(9) 2007 Full Version .pdf
ASME IX(9)  2007 Full Version       .pdfASME IX(9)  2007 Full Version       .pdf
ASME IX(9) 2007 Full Version .pdf
 
Cosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdfCosmetic shop management system project report.pdf
Cosmetic shop management system project report.pdf
 

Linked list

  • 1. LINKED LIST OPERATIONS By, Shashank Shetty Assistant Professor, Department of ISE NMAMIT, Nitte Shashankshetty@nitte.edu.in
  • 2. Inserting a node into a SLL There are many ways you might want to insert a new node into a list: As the new first element As the new last element  In the middle of the two nodes or in some designated position. Shashankshetty@nitte.edu.in
  • 3. 25 1) Insert a node at the beginning of the list // Algorithm : Insertion (Item) // Description : Inserts a node at the beginning of the SLL Step1: Start Step 2: NewNode=getnode() NewNode -> link = NULL NewNode -> info = Item Step 3: [ If the Linked list is empty, then the New Node Created is a first node or Head Node] if(Head==NULL) Head=NewNode return End if Step 4: [If the linked list is not empty] NewNode -> link= Head Head= NewNode Free(NewNode) Step 5: Return (Stop) Item NULL NewNode Head NULL 4 6 NULL Head 254 6 NULLItem Head Shashankshetty@nitte.edu.in
  • 4. 2) Insert a node at the End of the list // Algorithm : Insertion (Item) // Description : Inserts a node at the End of the SLL Step1: Start Step 2: NewNode=getnode() NewNode -> link = NULL NewNode -> info = Item Step 3: [ If the Linked list is empty, then the New Node Created is a first node or Head Node] if(Head==NULL) Head=NewNode return End if Step 4: [If the linked list is not empty] Cur= Head While (Cur-> link !=NULL) Cur=Cur->link end while Step 5: Cur -> link= NewNode Step 6: Free(NewNode) Free (Cur) Step 5: Return (Stop) 25 Item NULL NewNode Head NULL 4 6 NULL Head 625 item NULL4 Head Cur Cur Shashankshetty@nitte.edu.in
  • 5. Shashankshetty@nitte.edu.in 3) Insert a node at the middle of two nodes or at the designated position // Algorithm : Insertion (Item, position) // Description : Inserts a node at the middle or at the designated position of the SLL Step1: Start Step 2: NewNode=getnode() NewNode -> link = NULL NewNode -> info = Item Step 3: [ If the Linked list is empty, then the New Node Created is a first node or Head Node] if(Head==NULL) Head=NewNode return End if Step 4: [If the linked list is not empty] Cur= Head While (Cur!=position-1) Cur=Cur->link end while Cur1=Cur->link Step 5: Cur->link= NewNode NewNode->link= Cur1 Step 6: Free(NewNode) Free (Cur) Free(Cur1) Step 5: Return (Stop) 25 Item NULL NewNode Head NULL 4 6 NULL Head 625 item NULL4 Head Cur Cur 1 2 3 Let Us insert the new node at position 3!!! Cur1
  • 6. Shashankshetty@nitte.edu.in Deleting a node from SLL There are many ways you might want to delete a new node from a list: Delete first element Delete last element  From the middle of the two nodes or in some designated position.
  • 7. Shashankshetty@nitte.edu.in 25 1) Delete a node from the beginning of the list // Algorithm : Deletion (Item) // Description : Delete a node from the beginning of the SLL Step1: Start Step 2: [If Empty List] If (Head==NULL) Display (“List Empty”) Return EndIf Step 3: [If the linked list is not empty] Temp=Head Head=Head-> link display (temp->info) Free(Temp) Step 4: Return (Stop) Head NULL 4 6 NULL Head 25 6 NULL Head List Empty Temp
  • 8. Shashankshetty@nitte.edu.in 25 2) Delete a node from the End of the list // Algorithm : Deletion (Item) // Description : Delete a node from the end of the SLL Step1: Start Step 2: [If Empty List] If (Head==NULL) Display (“List Empty”) Return EndIf Step 3: [If the linked list is not empty] Temp=Head While(temp->link!=NULL) temp1=temp temp=temp->link end while temp1->next=NULL display (temp->info) Free(Temp) Step 4: Return (Stop) Head NULL 4 6 NULL Head NULL Temp1 List Empty Temp TempTemp1 Temp NULL 25 Head 4
  • 9. Shashankshetty@nitte.edu.in 3) Delete a node from the Middle positionor from specified position // Algorithm : Deletion (Item, position) // Description : Delete a node from the specified position of the SLL Step1: Start Step 2: If(Position<=0 or position>length) Display(“Node position doenot exist”) EndIf Step 3: [If Empty List] If (Head==NULL) Display (“List Empty”) Return EndIf Step 3: [If the linked list is not empty] Temp=Head While(temp !=pos) temp1=temp temp=temp->link end while temp1->next=temp->next display (temp->info) Free(Temp) Step 4: Return (Stop)