Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
Line 262: Line 262:
a = quickSort(a)
a = quickSort(a)
In a Haskell fashion:
In a Haskell fashion:
import random
def qsort(L):
def qsort(L):
if len(L) <= 1: return L
if len(L) <= 1: return L
pivot = random.choice(L)
pivot, L = L[0], L[1:]
return qsort([lt for lt in L if lt < pivot]) + [pivot]*L.count(pivot) + \
return qsort([y for y in L if y <= pivot]) + [pivot] + \
qsort([gt for gt in L if gt > pivot])
qsort([y for y in L if y > pivot])


=={{header|Seed7}}==
=={{header|Seed7}}==