Jump to content

Sorting algorithms/Quicksort: Difference between revisions

→‎{{header|Python}}: use speaking variable names.
imported>MM
m (→‎{{header|Python}}: : un-pythonic to have "else:" after "if condition: … return", as superfluous.)
imported>MM
(→‎{{header|Python}}: use speaking variable names.)
Line 8,010:
 
=={{header|Python}}==
<syntaxhighlight lang="python">def quickSortquick_sort(arrsequence):
lesslesser = []
pivotListequal = []
moregreater = []
if len(arrsequence) <= 1:
return arrsequence
pivot = arrsequence[0]
for ielement in arrsequence:
if ielement < pivot:
lesslesser.append(ielement)
elif ielement > pivot:
moregreater.append(ielement)
else:
pivotListequal.append(ielement)
lesslesser = quickSortquick_sort(lesslesser)
moregreater = quickSortquick_sort(moregreater)
return lesslesser + pivotListequal + moregreater
 
 
a = [4, 65, 2, -31, 0, 99, 83, 782, 1]
a = quickSortquick_sort(a)
</syntaxhighlight>
 
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.