add remove, remove_last, sub_sort

This commit is contained in:
mantaru 2024-11-03 17:49:02 +01:00
parent 5a7cc1bc1d
commit 55182e5a47
3 changed files with 52 additions and 17 deletions

27
list.py
View File

@ -62,6 +62,15 @@ class Liste:
current = current.next
return None
def search_max(self):
current = self.head
m = 0
while current is not None:
if current.data >= m:
m = current.data
current = current.next
return m
def remove2(self, value):
# Iterative Lösung der Löschfunktion
if self.head is None:
@ -135,19 +144,15 @@ class Liste:
new_element = Element(value)
if self.head is None:
self.head = new_element
return
if self.head.data > value:
elif self.head.data > value:
new_element.next = self.head
self.head = new_element
return
current = self.head
while current.next is not None and current.next.data < value:
current = current.next
new_element.next = current.next
current.next = new_element
else:
current = self.head
while current.next is not None and current.next.data < value:
current = current.next
new_element.next = current.next
current.next = new_element
def sub_sort(self):
if self.head is not None:

26
list_klausur.py Normal file
View File

@ -0,0 +1,26 @@
class Element:
def __init__(self, data):
self.data = data
self.next = None
class Liste:
def __init__(self):
self.head = None
def insert(self, value):
new_element = Element(value)
new_element.next = self.head
self.head = new_element
def remove(self):
pass
def func(self):
current = self.head
m = 0
while current is not None:
if current.data >= m:
m = current.data
current = current.next
return m

14
main.py
View File

@ -15,14 +15,18 @@ print("Suche nach Wert 2:", liste.search(2).data if liste.search(2) else "Nicht
print("---")
liste.remove(1)
liste.show_list()
#liste.remove(1)
#liste.show_list()
# liste.insert_before(4, 2)
# print("Inhalt der Liste nach Einfügen von 1.5 vor 2:")
# liste.show_list()
#liste.insert_before(1, 2)
#print("Inhalt der Liste nach Einfügen von 1.5 vor 2:")
#liste.show_list()
#
# print("---")
# liste.remove_last()
# liste.remove_last()
# liste.show_list()
#liste.insert_sorted(5)
#liste.show_list()
print(liste.search_max())