diff --git a/list.py b/list.py index b5a01e1..0895dd6 100644 --- a/list.py +++ b/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,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: diff --git a/list_klausur.py b/list_klausur.py new file mode 100644 index 0000000..ac958d2 --- /dev/null +++ b/list_klausur.py @@ -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 diff --git a/main.py b/main.py index d8c87d4..d2de5f8 100644 --- a/main.py +++ b/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() \ No newline at end of file +# liste.show_list() + +#liste.insert_sorted(5) +#liste.show_list() +print(liste.search_max()) \ No newline at end of file