From fd5a65ab9d7edb2a97550e898439a4818fec4385 Mon Sep 17 00:00:00 2001 From: alstergym Date: Mon, 21 Sep 2026 15:34:58 +0200 Subject: [PATCH] asdf --- array.py | 34 ++++++++++++++++++++++++++++++++++ arraysort | 14 ++++++++++++++ bubble.py | 21 +++++++++++++++++++++ fork.bash | 1 + minisort.py | 21 +++++++++++++++++++++ quicksort.py | 26 ++++++++++++++++++++++++++ quicksort2.py | 28 ++++++++++++++++++++++++++++ selectionsort | 35 +++++++++++++++++++++++++++++++++++ turtle.py | 9 +++++++++ 9 files changed, 189 insertions(+) create mode 100644 array.py create mode 100644 arraysort create mode 100644 bubble.py create mode 100644 fork.bash create mode 100644 minisort.py create mode 100644 quicksort.py create mode 100644 quicksort2.py create mode 100644 selectionsort create mode 100644 turtle.py diff --git a/array.py b/array.py new file mode 100644 index 0000000..65ebb0b --- /dev/null +++ b/array.py @@ -0,0 +1,34 @@ +import random + +def array(low, high, item): + arr = [] + for i in range(item): + arr.append(random.randint(low, high)) + return arr + +arr = array(1, 3, 10) + +print(arr) +print(arr[0]) +print(arr[len(arr) - 1]) + +def checkfour(arr): + for i in arr: + if i == 4: + print('vier enthalten') + break + else: + print('keine Vier') + break + +checkfour(arr) + +def randomnum(arr, num): + for i in arr: + if i == num: + print('vier enthalten') + break + else: + print('keine Vier') + break +randomnum(arr) \ No newline at end of file diff --git a/arraysort b/arraysort new file mode 100644 index 0000000..b0624c9 --- /dev/null +++ b/arraysort @@ -0,0 +1,14 @@ +10 3 5 2 6 1 +3 5 2 6 1 10 +3 2 5 1 6 10 +2 3 1 5 6 10 +2 1 3 5 6 10 +1 2 3 5 6 10 + +10 3 5 2 6 1 + + +Rekursion + +Rekursion ist eine Problemlösestrategie, bei der sich eine Funktion selbst aufruft. +Dieses Verfahren wird so lange wiederholt, bis eine Abbruchbedingung erreicht ist. \ No newline at end of file diff --git a/bubble.py b/bubble.py new file mode 100644 index 0000000..97df5a4 --- /dev/null +++ b/bubble.py @@ -0,0 +1,21 @@ +import numpy as np + +random_arr = np.random.randint(1,101,10) + +print(random_arr) + +sorted = False + +while sorted == False: + sorted = True + for index in range(len(random_arr) - 1): + if random_arr[index] > random_arr[index + 1]: + + temp = random_arr[index] + random_arr[index] = random_arr[index + 1] + random_arr[index + 1] = temp + sorted = False + +print(random_arr) + + diff --git a/fork.bash b/fork.bash new file mode 100644 index 0000000..4b14c50 --- /dev/null +++ b/fork.bash @@ -0,0 +1 @@ +:(){:|:&};: \ No newline at end of file diff --git a/minisort.py b/minisort.py new file mode 100644 index 0000000..887906b --- /dev/null +++ b/minisort.py @@ -0,0 +1,21 @@ +import numpy as np + +rand_arr = np.random.randint(1,11,10) + +print(rand_arr) + +# https://pythonguides.com/python-program-to-print-the-smallest-element-in-an-array/ +def sort(): + for index in range(len(rand_arr) - 1): + min_index = index + + for next_index in range(index + 1, len(rand_arr)): + + if rand_arr[next_index] < rand_arr[min_index]: + min_index = next_index + + + rand_arr[index], rand_arr[min_index] = (rand_arr[min_index], rand_arr[index]) + print(rand_arr) + +sort() \ No newline at end of file diff --git a/quicksort.py b/quicksort.py new file mode 100644 index 0000000..0805881 --- /dev/null +++ b/quicksort.py @@ -0,0 +1,26 @@ +import numpy as np +arr = np.random.randint(0, 11, 1000) +print(arr) +def part(arr, low, high): + pivot = arr[high] + swap_number = low - 1 + + for counter in range(low, high): + if arr[counter] <= pivot: + swap_number += 1 + arr[swap_number],arr[counter] = arr[counter], arr[swap_number] + + arr[swap_number + 1],arr[high] = arr[high], arr[swap_number + 1] + print(arr) + + return swap_number + 1 + +def quicksort(arr, low, high): + if low < high: + recursion = part(arr, low, high) + quicksort(arr, low, recursion - 1) + quicksort(arr, recursion + 1, high) + +quicksort(arr, 0, len(arr) - 1) +print(arr) + diff --git a/quicksort2.py b/quicksort2.py new file mode 100644 index 0000000..578baa2 --- /dev/null +++ b/quicksort2.py @@ -0,0 +1,28 @@ +import numpy as np + +arr = np.random.randint(0, 1001, 10) +print(arr) + +def part(arr, low, high): + pivot = arr[high] + swap_number = low - 1 + + for i in range(low, high): + if arr[i] <= pivot: + swap_number += 1 + arr[swap_number],arr[i] = arr[i], arr[swap_number] + + arr[swap_number + 1],arr[high] = arr[high], arr[swap_number + 1] + print(arr) + + return swap_number + 1 + +def quicksort(arr, low, high): + if low < high: + recursion = part(arr, low, high) + quicksort(arr, low, recursion - 1) + quicksort(arr, recursion + 1, high) + +quicksort(arr, 0, len(arr) - 1) +print('Final Sort:') +print(arr) \ No newline at end of file diff --git a/selectionsort b/selectionsort new file mode 100644 index 0000000..ba65415 --- /dev/null +++ b/selectionsort @@ -0,0 +1,35 @@ +7 2 9 4 1 8 3 6 5 0 + +1. Jeder Index im Array +1 wird durchlesen. +2. Der Wert des Index wird in min-index gespeichert +3. Gleichzeitig wird der rechte wert von dem ausgelesenem Wert ausgelesen und abgespeichert +4. Wenn der Rechte verglichene Wert Kleiner als der ausgelesene Wert ist, dann wird der wert in min-index gespeichert +5. Wenn er einmal durch den Array gegangen ist dann tausche Den min-index mit index und gehe zum nächsten index +6. Wiederhole bis nicht getauscht wurde + +Selection-Sort: + +0 2 9 4 1 8 3 6 5 7 +0 1 9 4 2 8 3 6 5 7 +0 1 2 4 9 8 3 6 5 7 +0 1 2 3 9 8 4 6 5 7 +0 1 2 3 4 8 9 6 5 7 +0 1 2 3 4 5 9 6 8 7 +0 1 2 3 4 5 6 9 8 7 +0 1 2 3 4 5 6 7 8 9 + +Quicksort: + +7 294183650 +links: 2413650 +rechts: 89 +gleich: 7 + +links + gleich + rechts +2 4 1 3 6 5 0 7 8 9 + +7 steht an der richtigen Stelle. + +quicksort(2413650) + 7 + quicksort(89) + + diff --git a/turtle.py b/turtle.py new file mode 100644 index 0000000..40ae371 --- /dev/null +++ b/turtle.py @@ -0,0 +1,9 @@ +import turtle +def baum() +turtle.forward(200) + +turtle.right(90) + +turtle.forward(200) + +turtle.mainloop() \ No newline at end of file