len() funktion, fix pop() funktion, assertions in starten.py

This commit is contained in:
alstergym
2026-10-02 09:00:32 +02:00
parent bbcb0c66d7
commit 399784d458
2 changed files with 36 additions and 4 deletions
+24 -3
View File
@@ -55,17 +55,38 @@ class LinkedList:
def pop(self) -> int | None:
if self.head is None:
self.head = None
return None
node = self.head
assert node is not None
if node.next is None:
data = node.data
self.head = None
return data
assert node.next is not None
while True:
if node.next is None:
return node.data
prev_node = node
node = node.next
if node.next is None:
data = node.data
prev_node.next = None
return data
def len(self) -> int:
node = self.head
i = 0
while node is not None:
node = node.next
i += 1
return i
def print(self):
node = self.head
while node is not None: