Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
(added J solution) |
|||
Line 261: | Line 261: | ||
a = [4, 65, 2, -31, 0, 99, 83, 782, 1] |
a = [4, 65, 2, -31, 0, 99, 83, 782, 1] |
||
a = quickSort(a) |
a = quickSort(a) |
||
In a Haskell fashion: |
|||
import random |
|||
def qsort(L): |
|||
if len(L) <= 1: return L |
|||
pivot = random.choice(L) |
|||
return qsort([lt for lt in L if lt < pivot]) + [pivot] + \ |
|||
qsort([ge for ge in L if ge >= pivot]) |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |