Skip to content

Instantly share code, notes, and snippets.

@fmasanori
Last active August 9, 2021 01:41
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save fmasanori/4673057 to your computer and use it in GitHub Desktop.
Save fmasanori/4673057 to your computer and use it in GitHub Desktop.
Quicksort
def quicksort(v):
if len(v) <= 1:
return v
pivot = v[0]
equals = [x for x in v if x == pivot]
smaller = [x for x in v if x < pivot]
higher = [x for x in v if x > pivot]
return quicksort(smaller) + equals + quicksort(higher)
print (quicksort([5, 7, 9, 3, 4, 0, 2, 1, 6, 8]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment