Skip to content

Instantly share code, notes, and snippets.

@kevinslin
Created December 20, 2011 16:00
Show Gist options
  • Save kevinslin/1502067 to your computer and use it in GitHub Desktop.
Save kevinslin/1502067 to your computer and use it in GitHub Desktop.
Quicksort
def quicksort(lst, left=0, right=None):
if right is None:
right = len(lst) - 1
l = left
r = right
if l <= r:
mid = lst[(left+right)/2]
while l <= r:
while l <= right and lst[l] < mid:
l += 1
while r > left and lst[r] > mid:
r -= 1
if l <= r:
lst[l], lst[r] = lst[r], lst[l]
if l != r:
lst.log()
l+=1
r-=1
if left < r:
quicksort(lst, left, r)
if l < right:
quicksort(lst, l, right)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment