add remove, remove_last, sub_sort
This commit is contained in:
parent
5a7cc1bc1d
commit
55182e5a47
17
list.py
17
list.py
@ -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,17 +144,13 @@ 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
|
||||
|
||||
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
|
||||
|
||||
|
26
list_klausur.py
Normal file
26
list_klausur.py
Normal 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
14
main.py
@ -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())
|
Loading…
Reference in New Issue
Block a user