Skip to content

Instantly share code, notes, and snippets.

@bcambel
Created November 6, 2014 11:24
Show Gist options
  • Save bcambel/ab059523cafee46ff173 to your computer and use it in GitHub Desktop.
Save bcambel/ab059523cafee46ff173 to your computer and use it in GitHub Desktop.
Quick sort
def qsort(arr):
print "ALL", arr
if len(arr) <= 1:
return arr
else:
left = qsort([x for x in arr[1:] if x<arr[0]])
middle = [arr[0]]
right = qsort([x for x in arr[1:] if x>=arr[0]])
print "LMR", left, middle, right
return left + middle + right
qsort([2, 7, 1, -2, 56, 5, 3, 45, 1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment