Skip to content
Programmingoneonone
Programmingoneonone
  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
  • Work with US
Programmingoneonone
Programmingoneonone

Deletion in Linked list | Data Structure

YASH PAL, 12 May 202014 August 2025

Deletion in Linked list – As we know for performing operations on the linked list we need to find the reference to the node of the list. so to delete a node from any position in the linked list we need to first find the reference of the node.

And if you don’t know how to find the reference of a node in the linked list then first complete read this post – Operations on a linked list

Deletion in Linked List

  1. Deletion of the first node
  2. Deletion of the only node
  3. Deletion in between the node
  4. Deletion at the end of the list

Deletion of the first node from the linked list

as you see we have a linked list that contains 5 items in it.

delection of the first node from the linked list

to delete the first node of the list we need to point the start variable of the linked list to the second node of the list.

delection of the first node from the linked list

so now the first node of the linked list is deleted.

delection of the first node from the linked list
def delete_first_node(self):
    if self.start is None:
        return    self.start = self.start.link

Deletion of the only node from the linked list

like if we have a list that has only one node.

Deletion of the only node from linked list

then to delete the only node of the list we store the null or None value to the start variable.

Deletion of the only node from linked list

so now our list becomes empty.

Deletion of the only node from linked list
self.start = None

Deletion in between the nodes of a linked list

To delete a node between the nodes of the linked list first we need to find the reference of the predecessor of the node that we want to delete. like in the example given below we want to delete the second and fourth nodes. so we want to delete the node that contains the value 30.

so we need to find the reference to the node that comes before the node that contains the value 30.

Deletion in between the nodes of a linked list

then we refer the p node to the node that comes second after the node p. as you see in the image given below.

Deletion in between the nodes of a linked list

now the node is deleted from the list.

Deletion in between the nodes of a linked list

Deletion at the end of the linked list.

to delete the last node we need a reference to the second last node of the linked list. as we see in the image given below.

Deletion in between the nodes of a linked list

after that, we set the linked part of p to null or None.

Deletion in between the nodes of a linked list

so now the last node of the linked list is deleted.

Deletion in between the nodes of a linked list
def delete_last_node(self):

    if self.start is None:
        return
    if self.start.link is None:
        self.start = None        return
    p = self.start
    while p.link.link is not None:
        p = p.link
    p.link = None
Computer Science Tutorials Data Structures Tutorials computer scienceData Structure

Post navigation

Previous post
Next post

Related website

The Computer Science

Pages

  • About US
  • Contact US
  • Privacy Policy

Programing Practice

  • C Programs
  • java Programs

HackerRank Solutions

  • C
  • C++
  • Java
  • Python
  • Algorithm

Other

  • Leetcode Solutions
  • Interview Preparation

Programming Tutorials

  • DSA
  • C

CS Subjects

  • Digital Communication
  • Human Values
  • Internet Of Things
  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes