A Beginner’s Guide to Linked Lists: Part 1 — Building Blocks and Fundamental Concepts
Linked List is a form of a sequential collection and it does not have to be in order.
A linked list is made up of independent nodes that may contain any type of data and each node has a reference to the next node in the link. example consider a train, where each train car as a Node ( value : consider as Passenger + Next pointer : as a reference), It has head, tail, and links.
Success is neither magical nor mysterious. Success is the natural consequence of consistently applying the basic fundamentals.
Jim Rohn
Step 1: Create a simple Node. Node is made up of 2 factors : value and the next pointer, So create a simple Class of Node and define the function.
Step 2 : Create a Linked List. It consist of head and tail pointing towards the node.
Step 3 : Create an Empty Linked List. Here Node is absent.
I have just three things to teach: simplicity, patience, compassion. These three are your greatest treasures. — Lao Tzu
# Creating a Node : Node = Value + Next Pointer
class Node:
def __init__(self,value):
self.value=value
self.next=None
# Creating LinkedList : Head and Tail pointing towards the node
class LinkedList:
def __init__(self,value):
new_node=Node(value)
self.head=new_node
self.tail=new_node
self.length=1
new_Linked_list=LinkedList(10)
print(new_Linked_list.head.value) #10
print(new_Linked_list.length) #1
# Empty Linked list
class LinkedList:
def __init__(self):
self.head=None
self.tail=None
self.length=0
Coding like poetry should be short and concise. ― Santosh Kalwar
Thank you. If it is helpful, please follow me. Waiting for my first 100 followers !