Ä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
+22
View File
@@ -0,0 +1,22 @@
# Verkettete Liste -- Linked Lists
Aufgabe von itslearning:
## Aufgabe 1
> Beschreiben Sie den Auszug aus liste.py zeilenweise, schriftlich
1. importiere die Knoten Klasse aus der datei knoten.py
2. start von Difinition der Klasse Liste
3. Definition des Konstruktors
4. Konstruktor-Body: ein neues Objekt wird kreiert, mit dem Attribut head gleich None
5. (leer)
6. Definition einer Methode zum Ausgeben der Liste in die Konsole
7. (leer)
8. Attribut head wird in aktueller_knoten zwischengespeichert
9. (leer)
10. Schleife, die alle Knoten der Liste durchläuft
11. (leer)
12. Daten des aktuellen Knoten werden in der Konsole ausgegeben
13. (leer)
14. aktueller_knoten wird auf den ihm folgenden Knoten gesetzt
+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
+17
View File
@@ -0,0 +1,17 @@
from linked_list import LinkedList
list = LinkedList()
list.push(123)
list.push(456)
list.push(789)
list.print()
print(list.pop())
print(list.pop())
print(list.pop())
# node3 = Node(333)
# node2.next = node3
# print(node1.data, node1.next.data, node2.next)