class Node:
def __init__(self, data = None, next = None):
self.data = data
self.next = next
class LinkedList(Node):
def __init__(self, l_size = 0, head = None, tail = None):
Node.__init__(self)
self.l_size = 0
self.head = head
self.tail = tail
def add(self, data):
n = Node(data, None)
if(self.l_size == 0):
self.head.next = n
self.head.data = n.data
else:
self.tail.next = n
self.tail.data = n.data
n = n.next
print(n)
self.tail = n
self.l_size += 1
return True
l = LinkedList()
l.add(7)
l.add(8)
l.add(2)
I'm just trying to achieve (h)-> 7 -> 8 -> 2 <- (l)
Where (h) and (l) are the head and tail pointers respectively. The way I'm implementing this the LL is basically the head and the tail pointers, the Nodes chain together on their own, that's why I made Node a super class.
headalwaysNone? So, inadd(),head.nextwill fail.headwhich is None, and it remains None throughout. Soself.head.nextwon't work.