I made a linked list using the following code.
# 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 the master class contains a Node object
class LinkedList:
# Function to initialize head
def __init__(self):
self.head = None
And added values to it as:
if __name__=='__main__':
# Start with the empty list
llist = LinkedList()
llist.head = Node(1)
llist.head.next = Node(2)
llist.head.next.next = Node('3a')
Then I tried to make a function to print the data of the linkedlist as:
def printl(llist):
temp = llist.head
while(temp):
return temp.data
temp = temp.next
But it returned only the first value i.e 1. How can I print all the data present in the linked list?