Skip to content

Instantly share code, notes, and snippets.

@christopher-beckham
Created April 19, 2014 12:57
Show Gist options
  • Save christopher-beckham/11083727 to your computer and use it in GitHub Desktop.
Save christopher-beckham/11083727 to your computer and use it in GitHub Desktop.
def quicksort(arr):
if arr == []:
return []
if len(arr) == 1:
return arr
m = len(arr) / 2
pivot = arr[m]
less = [ arr[x] for x in range(0, len(arr)) if arr[x] <= pivot and x != m ]
greater = [ arr[x] for x in range(0, len(arr)) if arr[x] > pivot and x != m ]
return quicksort(less) + [pivot] + quicksort(greater)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment