Sorting algorithms/Quicksort: Difference between revisions

Content added Content deleted
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
else:
pivot = arr[0]
pivot = arr[0]
for i in arr:
for i in arr:
if i < pivot:
if i < pivot:
less.append(i)
less.append(i)
elif i > pivot:
elif i > pivot:
more.append(i)
more.append(i)
else:
else:
pivotList.append(i)
less = quickSort(less)
pivotList.append(i)
less = quickSort(less)
more = quickSort(more)
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)</syntaxhighlight>
a = quickSort(a)
</syntaxhighlight>


In a Haskell fashion --
In a Haskell fashion --