Sorting algorithms/Quicksort: Difference between revisions
Content added Content deleted
Bwana Pete (talk | contribs) |
imported>MM m (→{{header|Python}}: : un-pythonic to have "else:" after "if condition: … return", as superfluous.) |
||
Line 8,016: | Line 8,016: | ||
if len(arr) <= 1: |
if len(arr) <= 1: |
||
return arr |
return arr |
||
pivot = arr[0] |
|||
for i in arr: |
|||
if i < pivot: |
|||
less.append(i) |
|||
elif i > pivot: |
|||
more.append(i) |
|||
else: |
|||
pivotList.append(i) |
|||
less = quickSort(less) |
|||
pivotList.append(i) |
|||
more = quickSort(more) |
|||
return less + pivotList + more |
|||
return less + pivotList + more |
|||
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) |
||
</syntaxhighlight> |
|||
In a Haskell fashion -- |
In a Haskell fashion -- |