class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def displaylist(self):
if self.head is None:
print('Linked List is Empty. You have to enter the data in Linked list first')
else:
temp = self.head
while(temp!=None):
print(temp.data, end="-->")
temp = temp.next
if __name__ == "__main__":
llist = LinkedList()
llist.displaylist()
first = Node(0)
second = Node(10)
third = Node(20)
llist.head = first
first.next = second
second.next = third
llist.displaylist()
No comments:
Post a Comment