Created
June 11, 2020 14:09
-
-
Save vamsitallapudi/d6cdc37f82f154558ca4b6909215a80d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Node: | |
def __init__(self, data): | |
self.data = data # assigning the data passed | |
self.next = None # initializing the node as null | |
class LinkedList: | |
def __init__(self): | |
self.head = None | |
def traverse(self): | |
node = self.head | |
while node is not None: | |
print(node.data) | |
node = node.next | |
# actual code execution starts from here | |
if __name__ == '__main__': | |
linkedList = LinkedList() | |
linkedList.head = Node('a') | |
second = Node('b') | |
third = Node('c') | |
linkedList.head.next = second | |
second.next = third | |
linkedList.traverse() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment