diff --git a/Searching-algo/linked-list.py b/Searching-algo/linked-list.py new file mode 100644 index 0000000..355dc71 --- /dev/null +++ b/Searching-algo/linked-list.py @@ -0,0 +1,50 @@ +# A simple Python program to introduce a linked list + +# Node class +class Node: + + # Function to initialise the node object + def __init__(self, data): + self.data = data # Assign data + self.next = None # Initialize next as null + + +# Linked List class contains a Node object +class LinkedList: + + # Function to initialize head + def __init__(self): + self.head = None + + +# Code execution starts here +if __name__=='__main__': + + # Start with the empty list + llist = LinkedList() + + llist.head = Node(1) + second = Node(2) + third = Node(3) + + ''' + Three nodes have been created. + We have references to these three blocks as head, + second and third + + ''' + + llist.head.next = second; # Link first node with second + + ''' + Now next of first Node refers to second. So they + both are linked. + ''' + + second.next = third; # Link second node with the third node + + ''' + Now next of second Node refers to third. So all three + nodes are linked. + + ''' \ No newline at end of file