ich hab dieses quicksort programmiert:
def quicksort2(a): # hoare
if len(a) < 2:
return a
r1, r2 = 0, len(a)-1
pivot = a[random.randint(0,r2)]
while r1 < r2:
while a[r1] < pivot and r1 < r2:
r1 += 1
while a[r2] > pivot and r1 < r2:
r2 -= 1
a[r1], a[r2] = a[r2], a[r1]
r1,r2 = r1+1,r2-1
return quicksort2(a[:r1]) + quicksort2(a[r1:])
und das Ergebnis ist fast richtig, lediglich werden manchmal Zahlen im Ergebnis vertauscht. Ich hab schon mehrere gefragt, was das Problem ist, aber nicht mal ein Informatiklehrer konnte mir helfen. Auch chatgpt hat nur Schmutz geliefert, und deswegen frag ich hier. Und falls ihr denkt, ihr habt es, probiert es erst aus, weil das jeder bisher meinte.
Danke im vorraus.