28.09.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import random
|
||||
import time
|
||||
|
||||
|
||||
def quicksort(array, links, rechts):
|
||||
if links < rechts:
|
||||
pivot = array[rechts]
|
||||
i = links - 1
|
||||
|
||||
for j in range(links, rechts):
|
||||
if array[j] <= pivot:
|
||||
i += 1
|
||||
array[i], array[j] = array[j], array[i]
|
||||
|
||||
array[i + 1], array[rechts] = array[rechts], array[i + 1]
|
||||
|
||||
quicksort(array, links, i)
|
||||
quicksort(array, i + 2, rechts)
|
||||
|
||||
|
||||
# 1000 unterschiedliche Zahlen zwischen 1 und 100.000
|
||||
data = random.sample(range(1, 100001), 1000)
|
||||
|
||||
print("=" * 40)
|
||||
print(" QUICKSORT")
|
||||
print("=" * 40)
|
||||
|
||||
startzeit = time.perf_counter()
|
||||
|
||||
quicksort(data, 0, len(data) - 1)
|
||||
|
||||
endzeit = time.perf_counter()
|
||||
|
||||
print("\nSortierung abgeschlossen!")
|
||||
print("-" * 40)
|
||||
print("Anzahl Zahlen: ", len(data))
|
||||
print("Benötigte Zeit: ", endzeit - startzeit, "Sekunden")
|
||||
print("-" * 40)
|
||||
|
||||
print("\nErste 20 Zahlen des sortierten Arrays:")
|
||||
print(data[:20])
|
||||
|
||||
print("=" * 40)
|
||||
|
||||
Reference in New Issue
Block a user