Tell us what’s happening:
Can someone please help me as to why my code is wrong?
Pretty sure I am checking while the next node is none, assigning the next node to current. If you think there is an error with my logic in the condition, please point that out so that I can figure out the criteria
Your code so far
class LinkedList:
class Node:
def __init__(self, element):
self.element = element
self.next = None
def __init__(self):
self.length = 0
self.head = None
def is_empty(self):
return self.length == 0
def add(self, element):
node = self.Node(element)
if self.is_empty():
self.head = node
# User Editable Region
else:
current_node = self.head
while not (current_node.next is None):
current_node = current_node.next
# User Editable Region
my_list = LinkedList()
print(my_list.is_empty())
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/146.0.0.0 Safari/537.36
Challenge Information:
Build a Linked List - Step 12