Skip to content

Instantly share code, notes, and snippets.

@abarax
Last active December 18, 2015 14:08
Show Gist options
  • Save abarax/5794691 to your computer and use it in GitHub Desktop.
Save abarax/5794691 to your computer and use it in GitHub Desktop.
def quicksort(ls, low, high):
if high - low > 0:
pivot = partition(ls, low, high)
quicksort(ls, low, pivot-1)
quicksort(ls, pivot+1, high)
def partition(ls, low, high):
pivot = ls[high]
firsthigh = low
for i in range(low, high):
if ls[i] < pivot:
ls[i], ls[firsthigh] = ls[firsthigh], ls[i]
firsthigh += 1
ls[high], ls[firsthigh] = ls[firsthigh], ls[high]
return firsthigh
l = [124, 845, 674, 632, 697, 351, 975, 487, 841, 258]
quicksort(l, 0, len(l)-1)
print(l)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment