Linked List Program in Python – Create Linked List, Add Node, Iterrate and Print Data

Lets try to create Linked List in Python as part of out Data structure Tutorial.

Problem Statement 

Create Linked List Basic Program in Python.

Solution

Lets understand the Very basic about Linked List –

  • Linked List are dynamic array type data structure where nodes and allocated on the fly i.e. dynamically and address/link or next node is maintained by reference/pointer in previous node so that it can be iterated.
  • Linked List has two field – Data and Next  –
    Linked List Node {
    Data ;  // Data is being stored here
    Next ;  // It contains the reference to next node or empty if if last node.
    }
  • There is Root Node which is like starting node which is kept at the first node always for iteration.
  • Linked List Operations : 
    • Adding New Node -New node is added when new data is added. Create new Node and set it at the end of the linked list.
    • Printing List Data – Start printing data from root till last node, we traverse through each node and move forward next pointer from previous node to next.
    • Delete the Node – Deletion node from Linked List is like removing link of the node which has to be deleted. Keep a reference to previous node of the data and once you find the node unlink it and point previous node pointer to next of data node.

Python Program

Here is standalone python program which creates basic linked list, add 5 nodes and print the data.

 

 

Let us know if you find any issue with above program.

tags : basic linked list program in python, linked list program in python, python linked list program, create linked list , linked list in python, basic linked list program, data structure in python, python ds programs, linkedlist delete node, ll program in python.

2 Comments

Add Comment

%d bloggers like this: