SlideShare a Scribd company logo
1 of 11
Deletion from
the single
linked list
• Removing a node from the linked list
• Deletion involves three cases :
• Case 1 : Delete the first node present in the list
• Case 2 : Delete the last node present in the list
• Case 3 : Delete any node present in the list
Delete the first node in the list
• Procedure:
• Check if the header points to NULL. If so, return “ no nodes present in
the list. Deletion is impossible.”
• Otherwise :
• 1. Delete the first node by altering the LINK Fields
• 2. The header node link field points to the second node in the list.
Algorithm:
1. Ptr = HEADER  LINK
2. If (Ptr = NULL ) then
3. print “ The list is empty: No deletion”
4. Exit
5. Else
6. Ptr1=ptrLINK
7. HEADERLINK = Ptr1
8. ReturnNode(Ptr)
9. Endif
10. Stop
Delete the last node:
• Procedure:
• Check if the header points to NULL. If so, return “ no nodes present in
the list. Deletion is impossible.”
• Otherwise :
• 1. Delete the last node by altering the LINK Fields
2. Take a variable called ptr1, store the current position in ptr and
compare the current node pointer points to NULL Value.
• 3. Remove the last node.
Algorithm:
1. Ptr = HEADER  LINK
2. If (Ptr = NULL ) then
3. print “ The list is empty: No deletion”
4. Exit
5. Else
6. While (ptr  LINK != NULL) do
7. ptr1=ptr
8. ptr=ptrLINK
9. endwhile
10. ptr1LINK=NULL
11. endif
12. stop
Delete any node:
1. ptr1=HEADER
2. If(ptr1=NULL)
3. print “ no nodes in the list, deletion not possible”
4. Else
5. ptr=ptr1 LINK
6. while(ptr!= NULL) do
7. if(ptr DATA != KEY) then
8. ptr1=ptr
9. ptr=ptrLINK
10. else
11. ptr1LINK = ptrLINK
12. returnnode(ptr)
13. exit
14. endif
15. endwhile
16. Stop
2.4 Deletion of a node from single linked list.pptx
2.4 Deletion of a node from single linked list.pptx

More Related Content

Similar to 2.4 Deletion of a node from single linked list.pptx

Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
ssuser7319f8
 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptxData structures linked list introduction.pptx
Data structures linked list introduction.pptx
Kalpana Mohan
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
student
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
MeghaKulkarni27
 

Similar to 2.4 Deletion of a node from single linked list.pptx (20)

Lect 11-12 Zaheer Abbas
Lect 11-12 Zaheer AbbasLect 11-12 Zaheer Abbas
Lect 11-12 Zaheer Abbas
 
Unit 5 linked list
Unit   5 linked listUnit   5 linked list
Unit 5 linked list
 
VCE Unit 02 (1).pptx
VCE Unit 02 (1).pptxVCE Unit 02 (1).pptx
VCE Unit 02 (1).pptx
 
Team 10
Team 10Team 10
Team 10
 
Link list 2
Link list 2Link list 2
Link list 2
 
Doubly & Circular Linked Lists
Doubly & Circular Linked ListsDoubly & Circular Linked Lists
Doubly & Circular Linked Lists
 
Dounly linked list
Dounly linked listDounly linked list
Dounly linked list
 
5.Linked list
5.Linked list 5.Linked list
5.Linked list
 
Linked list part-3
Linked list part-3Linked list part-3
Linked list part-3
 
Revisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queueRevisiting a data structures in detail with linked list stack and queue
Revisiting a data structures in detail with linked list stack and queue
 
LEC3-DS ALGO(updated).pdf
LEC3-DS  ALGO(updated).pdfLEC3-DS  ALGO(updated).pdf
LEC3-DS ALGO(updated).pdf
 
Data structures linked list introduction.pptx
Data structures linked list introduction.pptxData structures linked list introduction.pptx
Data structures linked list introduction.pptx
 
Circular link list.ppt
Circular link list.pptCircular link list.ppt
Circular link list.ppt
 
Linked List - Insertion & Deletion
Linked List - Insertion & DeletionLinked List - Insertion & Deletion
Linked List - Insertion & Deletion
 
Trees
TreesTrees
Trees
 
header, circular and two way linked lists
header, circular and two way linked listsheader, circular and two way linked lists
header, circular and two way linked lists
 
linked list
linked listlinked list
linked list
 
linkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptxlinkedlist-130914084342-phpapp02.pptx
linkedlist-130914084342-phpapp02.pptx
 
Data Structures with C Linked List
Data Structures with C Linked ListData Structures with C Linked List
Data Structures with C Linked List
 
ds 4Linked lists.ppt
ds 4Linked lists.pptds 4Linked lists.ppt
ds 4Linked lists.ppt
 

More from Sujan527908 (8)

vastu tajmahal.pptx
vastu tajmahal.pptxvastu tajmahal.pptx
vastu tajmahal.pptx
 
Operating system.pptx
Operating system.pptxOperating system.pptx
Operating system.pptx
 
buildingby-laws-170216060116 ppt.pptx
buildingby-laws-170216060116 ppt.pptxbuildingby-laws-170216060116 ppt.pptx
buildingby-laws-170216060116 ppt.pptx
 
silence.pptx
silence.pptxsilence.pptx
silence.pptx
 
1.4 Sorting.pptx
1.4 Sorting.pptx1.4 Sorting.pptx
1.4 Sorting.pptx
 
Stepper Motor .pptx
Stepper Motor .pptxStepper Motor .pptx
Stepper Motor .pptx
 
freindhsipppt-191019124250.pptx
freindhsipppt-191019124250.pptxfreindhsipppt-191019124250.pptx
freindhsipppt-191019124250.pptx
 
Presentation.pptx
Presentation.pptxPresentation.pptx
Presentation.pptx
 

Recently uploaded

Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
EADTU
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
Peter Brusilovsky
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
CaitlinCummins3
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
中 央社
 

Recently uploaded (20)

Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of TransportBasic Civil Engineering notes on Transportation Engineering & Modes of Transport
Basic Civil Engineering notes on Transportation Engineering & Modes of Transport
 
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
Transparency, Recognition and the role of eSealing - Ildiko Mazar and Koen No...
 
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH FORM 50 CÂU TRẮC NGHI...
 
Improved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio AppImproved Approval Flow in Odoo 17 Studio App
Improved Approval Flow in Odoo 17 Studio App
 
Supporting Newcomer Multilingual Learners
Supporting Newcomer  Multilingual LearnersSupporting Newcomer  Multilingual Learners
Supporting Newcomer Multilingual Learners
 
SPLICE Working Group: Reusable Code Examples
SPLICE Working Group:Reusable Code ExamplesSPLICE Working Group:Reusable Code Examples
SPLICE Working Group: Reusable Code Examples
 
OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...OS-operating systems- ch05 (CPU Scheduling) ...
OS-operating systems- ch05 (CPU Scheduling) ...
 
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
TỔNG HỢP HƠN 100 ĐỀ THI THỬ TỐT NGHIỆP THPT TOÁN 2024 - TỪ CÁC TRƯỜNG, TRƯỜNG...
 
AIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.pptAIM of Education-Teachers Training-2024.ppt
AIM of Education-Teachers Training-2024.ppt
 
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)ESSENTIAL of (CS/IT/IS) class 07 (Networks)
ESSENTIAL of (CS/IT/IS) class 07 (Networks)
 
Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"Mattingly "AI & Prompt Design: Named Entity Recognition"
Mattingly "AI & Prompt Design: Named Entity Recognition"
 
Including Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdfIncluding Mental Health Support in Project Delivery, 14 May.pdf
Including Mental Health Support in Project Delivery, 14 May.pdf
 
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
24 ĐỀ THAM KHẢO KÌ THI TUYỂN SINH VÀO LỚP 10 MÔN TIẾNG ANH SỞ GIÁO DỤC HẢI DƯ...
 
An overview of the various scriptures in Hinduism
An overview of the various scriptures in HinduismAn overview of the various scriptures in Hinduism
An overview of the various scriptures in Hinduism
 
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUMDEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
DEMONSTRATION LESSON IN ENGLISH 4 MATATAG CURRICULUM
 
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community PartnershipsSpring gala 2024 photo slideshow - Celebrating School-Community Partnerships
Spring gala 2024 photo slideshow - Celebrating School-Community Partnerships
 
SURVEY I created for uni project research
SURVEY I created for uni project researchSURVEY I created for uni project research
SURVEY I created for uni project research
 
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文會考英文
 
Trauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical PrinciplesTrauma-Informed Leadership - Five Practical Principles
Trauma-Informed Leadership - Five Practical Principles
 
How to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptxHow to Manage Website in Odoo 17 Studio App.pptx
How to Manage Website in Odoo 17 Studio App.pptx
 

2.4 Deletion of a node from single linked list.pptx

  • 2. • Removing a node from the linked list • Deletion involves three cases : • Case 1 : Delete the first node present in the list • Case 2 : Delete the last node present in the list • Case 3 : Delete any node present in the list
  • 3. Delete the first node in the list • Procedure: • Check if the header points to NULL. If so, return “ no nodes present in the list. Deletion is impossible.” • Otherwise : • 1. Delete the first node by altering the LINK Fields • 2. The header node link field points to the second node in the list.
  • 4.
  • 5. Algorithm: 1. Ptr = HEADER  LINK 2. If (Ptr = NULL ) then 3. print “ The list is empty: No deletion” 4. Exit 5. Else 6. Ptr1=ptrLINK 7. HEADERLINK = Ptr1 8. ReturnNode(Ptr) 9. Endif 10. Stop
  • 6. Delete the last node: • Procedure: • Check if the header points to NULL. If so, return “ no nodes present in the list. Deletion is impossible.” • Otherwise : • 1. Delete the last node by altering the LINK Fields 2. Take a variable called ptr1, store the current position in ptr and compare the current node pointer points to NULL Value. • 3. Remove the last node.
  • 7.
  • 8. Algorithm: 1. Ptr = HEADER  LINK 2. If (Ptr = NULL ) then 3. print “ The list is empty: No deletion” 4. Exit 5. Else 6. While (ptr  LINK != NULL) do 7. ptr1=ptr 8. ptr=ptrLINK 9. endwhile 10. ptr1LINK=NULL 11. endif 12. stop
  • 9. Delete any node: 1. ptr1=HEADER 2. If(ptr1=NULL) 3. print “ no nodes in the list, deletion not possible” 4. Else 5. ptr=ptr1 LINK 6. while(ptr!= NULL) do 7. if(ptr DATA != KEY) then 8. ptr1=ptr 9. ptr=ptrLINK 10. else 11. ptr1LINK = ptrLINK 12. returnnode(ptr) 13. exit 14. endif 15. endwhile 16. Stop