SlideShare a Scribd company logo
Insertion into linked lists
Deletion from linked
  list
1) Deletion from beginning
     deleting the node from the first position
2) Deletion from end
     deleting the node from the last position
3) Deletion from kth position
     deleting the node from a particular position
Deletion from linked list
 There are a few steps to delete a node from a link
 list
      Find the node.
      Store the link of node in a variable.
      Remove that node.
      Reconnect the linked list.
      Update the link to the beginning (if necessary).
 Deletion could not be done
    If the link list is empty
Deletion from beginning
                     Before deletion


Start =
link[12]


                        Deleting

               9
Start = link[ 12 ]
               9
       12    1004         99    1014   37
Deletion from end
                       Before deletion


Start =
link[12]


                          Deleting

 Start = link[12]


           12   1004        99    1014   37
Deletion from kth position
                      Before deletion

Start = link[12]


      12       1004    99        1014             45       1045            37

                      1004                       1014                  1045

                                    Deleting from 3rd position

Start = link[12]             Searching element
                                                           Element found




     12       1004     99        1014             45       1045            37

                      1004                       1014                  1045
Insertion into linked lists
Introduction

 Linked list is one of the fundamental data structures, and
  can be used to implement other data structures. In a linked
  list there are different numbers of nodes. Each node is
  consists of two fields. The first field holds the value or data
  and the second field holds the reference to the next node or
  null if the linked list is empty.
 Example:-
Adding An Element to a Linked
   List
Involves two steps:
 Finding the correct location.
 Doing the work to add the node.
Finding the Correct Location:-
Three possible positions:-
 The front.
 Somewhere in the middle.
 The end.
Three Types of Insertion
 To front
   No recursion needed.


 In order (in middle)
   To maintain sorted property.


 To end
   Get to the end, then add node.
5
        Inserting to the Front

Start      10       20       30       40




        Explain:-
         There is no work to find the correct
          location
         Empty or not, head will point to the
          right location
Inserting to the Middle             25




Start   5      10      20       30        Null   Null




  Used when order is important
  Go to the node that should
    follow the one to add
Inserting to the End                40




Start   5       10       20
                                //30        Null   Null




    Find the end of the list
     (when at NIL).
The Work to Add the Node
 Create the new node
 Fill in the data field
 Deal with the next field
   Point to nil (if inserting to end)
   Point to current (front or middle)


   temp <- new(Node)
   temp^.data <- new_data
   temp^.next <- current
   current <- temp

More Related Content

PPTX
Insertion sort
PPTX
Selection sort algorithm presentation, selection sort example using power point
PDF
Singly linked list
PPT
Counting Sort and Radix Sort Algorithms
PPTX
Searching and sorting
PPT
Selection sort
PPTX
Binary Search Tree
PPTX
Selection sort
Insertion sort
Selection sort algorithm presentation, selection sort example using power point
Singly linked list
Counting Sort and Radix Sort Algorithms
Searching and sorting
Selection sort
Binary Search Tree
Selection sort

What's hot (20)

PDF
Sorting Algorithms
PDF
Linear search algorithm
PPTX
Tree traversal techniques
PPTX
Quick sort-Data Structure
PPTX
Merge Sort
PPT
SEARCHING AND SORTING ALGORITHMS
PPT
Queue data structure
PPTX
Rahat &amp; juhith
PPTX
Searching
PPT
stack and queue array implementation in java.
PPTX
AVL Tree in Data Structure
PPTX
Brute force method
PDF
Quick Sort , Merge Sort , Heap Sort
PPTX
PPT
Insertion sort bubble sort selection sort
PDF
linear search and binary search
PPTX
Chapter 15 Lists
PPT
Linked lists
PPTX
Searching techniques
PDF
Linear search
Sorting Algorithms
Linear search algorithm
Tree traversal techniques
Quick sort-Data Structure
Merge Sort
SEARCHING AND SORTING ALGORITHMS
Queue data structure
Rahat &amp; juhith
Searching
stack and queue array implementation in java.
AVL Tree in Data Structure
Brute force method
Quick Sort , Merge Sort , Heap Sort
Insertion sort bubble sort selection sort
linear search and binary search
Chapter 15 Lists
Linked lists
Searching techniques
Linear search
Ad

Viewers also liked (11)

PPTX
Linked list
PPT
Sorting & Linked Lists
PPTX
Linked list
PPTX
Link list
PPTX
Single linked list
PPTX
Array implementation and linked list as datat structure
PDF
Bai toan va thuat toan
PPTX
Asymptotic Notation and Data Structures
PPTX
Linked List
PPT
Link List
PDF
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
Linked list
Sorting & Linked Lists
Linked list
Link list
Single linked list
Array implementation and linked list as datat structure
Bai toan va thuat toan
Asymptotic Notation and Data Structures
Linked List
Link List
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
Ad

Similar to Insertion into linked lists (20)

PDF
Singly Linked List
PPT
Operations on linked list
PDF
Linked Lists.pdf
PPTX
dokumen.tips_linked-list-ppt-5584a44be6115.pptx
PPT
Unit 2 linked list and queues
PPT
Lect 11-12 Zaheer Abbas
PPTX
csc211_lecture_21.pptx
PPT
Linked list
PPT
lecture four of data structures :Linked List-ds.ppt
PPTX
Type of linked list - Circular Linked list -
PDF
Chapter 3 Linkedlist Data Structure .pdf
PPTX
Unit 5 linked list
PPT
ds 4Linked lists.ppt
PPT
Linked list
PPT
List
PPT
Array linked list.ppt
PPTX
UNIT -4 Singly Linked List-kiruthika.pptx
PPT
Data Structures with C Linked List
PPTX
STACKS AND QUEUES CONCEPTS
PPSX
Data Structure (Double Linked List)
Singly Linked List
Operations on linked list
Linked Lists.pdf
dokumen.tips_linked-list-ppt-5584a44be6115.pptx
Unit 2 linked list and queues
Lect 11-12 Zaheer Abbas
csc211_lecture_21.pptx
Linked list
lecture four of data structures :Linked List-ds.ppt
Type of linked list - Circular Linked list -
Chapter 3 Linkedlist Data Structure .pdf
Unit 5 linked list
ds 4Linked lists.ppt
Linked list
List
Array linked list.ppt
UNIT -4 Singly Linked List-kiruthika.pptx
Data Structures with C Linked List
STACKS AND QUEUES CONCEPTS
Data Structure (Double Linked List)

Recently uploaded (20)

PDF
Sunset Boulevard Student Revision Booklet
PPTX
How to Manage Global Discount in Odoo 18 POS
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
How to Manage Bill Control Policy in Odoo 18
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
PPTX
Introduction and Scope of Bichemistry.pptx
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
PPTX
NOI Hackathon - Summer Edition - GreenThumber.pptx
PDF
Module 3: Health Systems Tutorial Slides S2 2025
PDF
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
PDF
Types of Literary Text: Poetry and Prose
PDF
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
PDF
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
Sunset Boulevard Student Revision Booklet
How to Manage Global Discount in Odoo 18 POS
Renaissance Architecture: A Journey from Faith to Humanism
How to Manage Bill Control Policy in Odoo 18
UPPER GASTRO INTESTINAL DISORDER.docx
Introduction and Scope of Bichemistry.pptx
Skill Development Program For Physiotherapy Students by SRY.pptx
Week 4 Term 3 Study Techniques revisited.pptx
vedic maths in python:unleasing ancient wisdom with modern code
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
The Final Stretch: How to Release a Game and Not Die in the Process.
NOI Hackathon - Summer Edition - GreenThumber.pptx
Module 3: Health Systems Tutorial Slides S2 2025
2.Reshaping-Indias-Political-Map.ppt/pdf/8th class social science Exploring S...
Types of Literary Text: Poetry and Prose
Phylum Arthropoda: Characteristics and Classification, Entomology Lecture
Electrolyte Disturbances and Fluid Management A clinical and physiological ap...
Open Quiz Monsoon Mind Game Final Set.pptx
102 student loan defaulters named and shamed – Is someone you know on the list?

Insertion into linked lists

  • 2. Deletion from linked list 1) Deletion from beginning deleting the node from the first position 2) Deletion from end deleting the node from the last position 3) Deletion from kth position deleting the node from a particular position
  • 3. Deletion from linked list  There are a few steps to delete a node from a link list Find the node. Store the link of node in a variable. Remove that node. Reconnect the linked list. Update the link to the beginning (if necessary).  Deletion could not be done If the link list is empty
  • 4. Deletion from beginning Before deletion Start = link[12] Deleting 9 Start = link[ 12 ] 9 12 1004 99 1014 37
  • 5. Deletion from end Before deletion Start = link[12] Deleting Start = link[12] 12 1004 99 1014 37
  • 6. Deletion from kth position Before deletion Start = link[12] 12 1004 99 1014 45 1045 37 1004 1014 1045 Deleting from 3rd position Start = link[12] Searching element Element found 12 1004 99 1014 45 1045 37 1004 1014 1045
  • 8. Introduction  Linked list is one of the fundamental data structures, and can be used to implement other data structures. In a linked list there are different numbers of nodes. Each node is consists of two fields. The first field holds the value or data and the second field holds the reference to the next node or null if the linked list is empty.  Example:-
  • 9. Adding An Element to a Linked List Involves two steps:  Finding the correct location.  Doing the work to add the node. Finding the Correct Location:- Three possible positions:-  The front.  Somewhere in the middle.  The end.
  • 10. Three Types of Insertion  To front  No recursion needed.  In order (in middle)  To maintain sorted property.  To end  Get to the end, then add node.
  • 11. 5 Inserting to the Front Start 10 20 30 40 Explain:-  There is no work to find the correct location  Empty or not, head will point to the right location
  • 12. Inserting to the Middle 25 Start 5 10 20 30 Null Null  Used when order is important  Go to the node that should follow the one to add
  • 13. Inserting to the End 40 Start 5 10 20 //30 Null Null  Find the end of the list (when at NIL).
  • 14. The Work to Add the Node  Create the new node  Fill in the data field  Deal with the next field  Point to nil (if inserting to end)  Point to current (front or middle) temp <- new(Node) temp^.data <- new_data temp^.next <- current current <- temp