+ 4

Is it a linkedlist ?

#Linked list class Node: def __init__(self, data, nxt=None): self.data = data self.nxt = nxt class LinkedList: def __init__(self): self.head = None; def insert(self, data): if (not self.head): self.head = Node(data) else: last_node = self.head self.head = Node(data) self.head.nxt = last_node def output(self): node = self.head while node: print(node.data, end=' -> ') node = node.nxt print(None) lnkdLst = LinkedList() lnkdLst.insert(1) lnkdLst.insert(5) lnkdLst.insert(9) lnkdLst.insert(13) lnkdLst.output()

12th Oct 2021, 5:26 AM
Aditya Dhiman
Aditya Dhiman - avatar
1 Réponse
+ 1
I am not sure . But I think it is the way how linked List is implemented in python
12th Oct 2021, 6:38 AM
Atul [Inactive]