+ 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()
1 ответ
+ 1
I am not sure . But I think it is the way how linked List is implemented in python