Skip to content

Instantly share code, notes, and snippets.

@rishi93
Created November 3, 2015 10:33
Show Gist options
  • Save rishi93/f34751152d046188ae2a to your computer and use it in GitHub Desktop.
Save rishi93/f34751152d046188ae2a to your computer and use it in GitHub Desktop.
Simple Quicksort in Python
def quicksort(arr):
if len(arr) <= 1:
return arr
else:
pivot = arr[0]
less = []
equal = []
more = []
for elem in arr:
if elem < pivot:
less.append(elem)
elif elem > pivot:
more.append(elem)
else:
equal.append(elem)
less = quicksort(less)
more = quicksort(more)
return less + equal + more
arr = [9,3,2,5,1,6,4,8,7]
print(quicksort(arr))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment