From 8ab7c0a8358ff3a5d7cd194e7f7ffcc0a4ebbb4c Mon Sep 17 00:00:00 2001 From: Oliver Hofmann Date: Tue, 23 Apr 2024 12:34:41 +0200 Subject: [PATCH] lecture --- SoSe24/lec03_sort_alg/quick_plot.py | 6 ++---- SoSe24/lec03_sort_alg/quick_sort.py | 6 +++++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/SoSe24/lec03_sort_alg/quick_plot.py b/SoSe24/lec03_sort_alg/quick_plot.py index c4f3cff..f957186 100644 --- a/SoSe24/lec03_sort_alg/quick_plot.py +++ b/SoSe24/lec03_sort_alg/quick_plot.py @@ -2,11 +2,9 @@ from SoSe24.algodat.foundation import AlgoDatArray, AlgoDatValue, read_int_seque import matplotlib.pyplot as plt import quick_sort as qs - - - if __name__ == "__main__": - filename = "../../seq3_sorted.txt" + filename = "../../seq3.txt" + #filename = "../../seq3_sorted.txt" dummy = read_int_sequence(filename) n = len(dummy) step = n // 100 diff --git a/SoSe24/lec03_sort_alg/quick_sort.py b/SoSe24/lec03_sort_alg/quick_sort.py index f44d975..dc87bbf 100644 --- a/SoSe24/lec03_sort_alg/quick_sort.py +++ b/SoSe24/lec03_sort_alg/quick_sort.py @@ -1,9 +1,10 @@ from SoSe24.algodat.foundation import AlgoDatArray, AlgoDatValue, read_int_sequence from time import perf_counter as pfc + def partition(z: AlgoDatArray, left: int, right: int) -> int: global pivot - pivot.value = z[right] + pivot.value = z[right] i = left j = right - 1 while i < j: @@ -21,6 +22,7 @@ def partition(z: AlgoDatArray, left: int, right: int) -> int: z[i], z[right] = z[right], z[i] return i + def median_pivot(z: AlgoDatArray, left: int, right: int) -> int: mid = left + (right - left) // 2 if z[left] < z[right]: @@ -49,6 +51,7 @@ def median_pivot(z: AlgoDatArray, left: int, right: int) -> int: z[left], z[right] = z[right], z[left] return partition(z, left, right) + def quick_sort(z: AlgoDatArray, left: int, right: int): if left < right: q = partition(z, left, right) @@ -56,6 +59,7 @@ def quick_sort(z: AlgoDatArray, left: int, right: int): quick_sort(z, left, q-1) quick_sort(z, q+1, right) + pivot = AlgoDatValue(0) if __name__ == "__main__":