Änderungen von letzter Stunde

Ich konnte nicht während des Unterrichts pushen.
Dieser Commit enthält die Änderungen,
von Nextcloud kopiert
This commit is contained in:
innin-jam
2026-09-27 18:23:48 +02:00
parent e6c8526691
commit 4a5c0c03fd
9 changed files with 85 additions and 4 deletions
+46
View File
@@ -0,0 +1,46 @@
from typing import Self
class Node:
def __init__(self, data: int):
self.data: int = data
self.next: Self | None = None
class LinkedList:
def __init__(self):
self.head: Node | None = None
# Definition der "append" Methode ich mag push und pop lieber >:)
def push(self, data: int):
if self.head is None:
self.head = Node(data)
return
node = self.head
assert node is not None
while True:
if node.next is None:
node.next = Node(data)
return
node = node.next
def pop(self) -> int | None:
if self.head is None:
self.head = None
return None
node = self.head
assert node is not None
while True:
if node.next is None:
return node.data
node = node.next
def print(self):
node = self.head
while node is not None:
print(node.data)
node = node.next