Skip to content
  • Linkedin
  • Youtube
  • Pinterest
  • Home
  • Privacy Policy
  • About
  • Contact
Programmingoneonone

Programmingoneonone

Programmingoneonone is a website that publishes daily tutorials, methods, guides, and articles on IT, Education, and technology.

  • Home
  • Human Values
  • DSA
  • IoT Tutorials
  • Interview Questions and Answers
  • Toggle search form
operations on linked list in data structures

Operations on the linked list

Posted on 12 May 202011 April 2023 By YASH PAL No Comments on Operations on the linked list

To perform operations like insertion, deletion, sorting, and searching on the linked list we need to find the reference to a particular node in a linked list. so today we are going to learn how we can find the reference to the nodes to perform operations on a linked list.

After completing this tutorial you are able to learn

  • Reference to the last node
  • Reference to the second last node
  • Reference to a node with particular info
  • Reference to the predecessor of a node with particular info
  • Reference to a node at a particular position

Finding a reference to the last node

Operations - Linked list in Data Structures and algorithms

as we know linked list contains the null or None value at the linked part of the last node of the list. so here is the code to find the reference to the last node of the linked list.

p = self.start
while p.link is not None:
    p = p.link

Note: here we first store the reference of the first node of the list in the p variable and then we continue to the next using the while loop till the value of the link part of a node is not equal to None.

Finding a reference to the second last node

Operations - Linked list in Data Structures and algorithms

here is the Python code to find the reference to the second last node of the list.

p = self.start
while p.link.link is not None:
    p = p.link

Note: here we run the while loop till the value of next to the next link of the node is equal to the null of None.

Finding a reference to a node with particular info

Operations - Linked list in Data Structures and algorithms

let’s assume we need to find the node that contains the value x. For example, if we need to find the node that contains the value 30 then here is the Python code to find the node with a particular value.

p = self.start
while p is not None:
    if p.info == x:
        break    p = p.link

Note: here we run the while loop till the last node of the list. and if we found the value of the node that is equal to the value that we are searching then the break statement stops the while loop.

Finding a reference to the predecessor of a node with particular info

Predecessor: predecessor node is the node before the node that contains the particular value. as you see in the image given below.

Operations - Linked list in Data Structures and algorithms

Note: here we need to find the reference to the predecessor of the node that contains the value x=30.

Here is the Python code to find the reference to the predecessor of the node with particular info.

p = self.start
while p.link is not None:
    if p.link.info == x:
        break    p = p.link

here we run the loop till the last node of the linked list and at every node, we check if the info part of the next to next node is equal to the value x or not. if the value is equal to the x then we break the loop.

Finding a reference to a node at a particular position

Operations - Linked list in Data Structures and algorithms

Here we need to find the node at position 3 as you see in the image given above.

Here is the Python code to find the node at a particular position.

p = self.start
i = 1
while i<k and p is not None:
    p = p.link
    i += 1

Note: here we run the while loop till the value of i is less than k and the last node to the list. and we increment the value of I at every iteration.

Computer Science Tutorials, Data Structures Tutorials Tags:computer science, Data Structure

Post navigation

Previous Post: Traversing in Linked List
Next Post: Big o notation examples with solutions

Related Tutorials

Reading input in c programming Reading Input in a C program C Programming Tutorials
The First C Program C Programming Tutorials
Compiling C Programs C Programming Tutorials
History of c programming language HISTORY OF C Programming Language C Programming Tutorials
c character sets C Character Sets C Programming Tutorials
c programming interview questions and answers C Programming Interview Questions and Answers C Programming Tutorials

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Pick your Subject

  • Internet of Things
  • Data Structures/Algorithms
  • Interview Preparation
  • Human Values
  • Java Interview Questions and Answers (2023)
    Thinking of becoming a Java developer? I must say it’s a good choice! Java is continuously named the most popular programming language. And the...

    Learn More “Java Interview Questions and Answers (2023)” »

  • Iot(Internet of things) in healthcare
    IoT in Healthcare
    IoMT (Internet of Medical Things) stands for devices that can collect and exchange data – either with users or other devices via the internet,...

    Learn More “IoT in Healthcare” »

  • four stages of iot solution for industry
    IoT for Industry
    In this post, we are going to learn about use cases of IoT for Industry and four stages for providing IoT solutions. Machine Diagnosis...

    Learn More “IoT for Industry” »

  • Iot for agricultural
    IoT in Agriculture
    IoT technology has realized smart wearables, connected devices, automated machines, and driverless cars. However, in agriculture, the IoT has brought the greatest impact. Amongst the challenges...

    Learn More “IoT in Agriculture” »

  • Iot for logistics
    IoT in Logistics and Supply Chain
    IoT applications for smart logistics and supply chain systems:  Logistics Fleet Tracking  To track the locations of the vehicles in real time, the vehicle...

    Learn More “IoT in Logistics and Supply Chain” »

  • Algorithms Tutorials
  • Basic Programming
  • C Programming Tutorials
  • C++ Tutorials
  • Compiler Design Tutorials
  • Computer Networks Tutorials
  • Computer Organization Tutorials
  • Computer Science Tutorials
  • Data Structures Tutorials
  • DBMS Tutorials
  • Developer Guide
  • Digital Communication
  • Digital Logic Tutorials
  • Internet of Things Tutorials
  • Internet Tutorials
  • Interview questions answers
  • Java Tutorials
  • Javascript Tutorials
  • Machine Learning Tutorials
  • Operating Systems Tutorials
  • Programming Tutorials
  • Projects
  • Tips&Tricks
  • Tools
  • VBScript Tutorials
  • Java Interview Questions and Answers (2023)
    Thinking of becoming a Java developer? I must say it’s a good choice! Java is continuously named the most popular programming language. And the...

    Learn More “Java Interview Questions and Answers (2023)” »

  • Iot(Internet of things) in healthcare
    IoT in Healthcare
    IoMT (Internet of Medical Things) stands for devices that can collect and exchange data – either with users or other devices via the internet,...

    Learn More “IoT in Healthcare” »

  • four stages of iot solution for industry
    IoT for Industry
    In this post, we are going to learn about use cases of IoT for Industry and four stages for providing IoT solutions. Machine Diagnosis...

    Learn More “IoT for Industry” »

  • Iot for agricultural
    IoT in Agriculture
    IoT technology has realized smart wearables, connected devices, automated machines, and driverless cars. However, in agriculture, the IoT has brought the greatest impact. Amongst the challenges...

    Learn More “IoT in Agriculture” »

  • Iot for logistics
    IoT in Logistics and Supply Chain
    IoT applications for smart logistics and supply chain systems:  Logistics Fleet Tracking  To track the locations of the vehicles in real time, the vehicle...

    Learn More “IoT in Logistics and Supply Chain” »

Copyright © 2023 Programmingoneonone.

Powered by PressBook Blog WordPress theme