class Node:
def __init__(self, data):
self.data = data
self.next = None
class LinkedList:
def __init__(self):
self.head = None
def __len__(self):
cur = self.head
count = 0
while cur is not None:
count += 1
cur = cur.next
return count
def append(self, item):
cur = self.head
while cur is not None:
cur = cur.next
cur.next = ?
I am trying to append to the linkedlist but I cant use 'cur.next' as cur has no attribute 'next'. Any hints on this?
Thanks!
My test cases:
def test_append_empty() -> None:
lst = LinkedList()
lst.append(1)
assert lst.head.data == 1
def test_append_one() -> None:
lst = LinkedList()
lst.head = Node(1)
lst.append(2)
assert lst.head.next.data == 2