diff --git a/README.md b/README.md index c8938b4..551326b 100644 --- a/README.md +++ b/README.md @@ -9,11 +9,12 @@ The .js cfiles can be found in \src-javascript The .py cfiles can be found in \src-python +# Array +An array is a collection of items stored at contiguous memory locations. Its used to store multiple items of the same type together. # Stack Stack is a linear data structure which follows a particular order in which the operations are performed. The order may be LIFO(Last In First Out) or FILO(First In Last Out). - # Linked List A linked list is a sequence of data structures, which are connected together via links. Linked List is a sequence of links which contains items. Each link contains a connection to another link. Linked list is the second most-used data structure after array. diff --git a/src-python/LinkedList.py b/src-python/LinkedList.py new file mode 100644 index 0000000..65891ae --- /dev/null +++ b/src-python/LinkedList.py @@ -0,0 +1,42 @@ +# A simple Python program for traversal of 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 + + # 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 + second.next = third + + llist.printList()