Skip to content

Instantly share code, notes, and snippets.

@alisianoi
Created December 3, 2016 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alisianoi/c39f710b256e3c5d75a9397928479d17 to your computer and use it in GitHub Desktop.
Save alisianoi/c39f710b256e3c5d75a9397928479d17 to your computer and use it in GitHub Desktop.
Quicksort implementations for the blog
def quicksort(xs):
def sort(xs, l, r):
if (l == r):
return
i, j = l, r
pivot = xs[(i + j) / 2]
while (i <= j):
while (xs[i] < pivot):
i += 1
while (pivot < xs[j]):
j -= 1
if (i <= j):
xs[i], xs[j] = xs[j], xs[i]
i += 1
j -= 1
i, j = 0, len(xs) - 1
sort(xs, i, j)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment