From 5ff19b442a46b8dc0546f1c2099a9853a0e2de9f Mon Sep 17 00:00:00 2001 From: unika-debug Date: Fri, 11 Oct 2019 01:07:42 +0530 Subject: [PATCH] LINKED LIST IN PYTHON #1377 CLOSES --- unika/unika.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 unika/unika.py diff --git a/unika/unika.py b/unika/unika.py new file mode 100644 index 000000000..d9f23624b --- /dev/null +++ b/unika/unika.py @@ -0,0 +1,29 @@ +# A simple Python program for implementing linked list in python +# Node class +class Node: + # Function to initialise the node object + def __init__(self, data): + self.data = data # Assign data + self.next = None +class LinkedList: + def __init__(self): + self.head = None + # This function prints contents of linked list + # starting from head + def printList(self): + temp = self.head + while (temp): + print temp.data, + temp = temp.next +# Code execution starts here +if __name__=='__main__': + # Start with the empty list + llist = LinkedList() + llist.head = Node(1) + second = Node(2) + third = Node(3) + + llist.head.next = second; # Link first node with second + second.next = third; # Link second node with the third node + + llist.printList()