Skip to content

Instantly share code, notes, and snippets.

@17twenty
Created June 2, 2013 17:19
Show Gist options
  • Save 17twenty/5694203 to your computer and use it in GitHub Desktop.
Save 17twenty/5694203 to your computer and use it in GitHub Desktop.
Quicksort Quick Implementation
#!/usr/bin/env python
"""Simple implementation of a quicksort"""
def quicksort(array):
if len(array) <= 1:
return array
pivot = array.pop(len(array) / 2) # Naive?
print "Chose pivot ", (pivot)
les = []
greater = []
for value in array:
if value <= pivot:
les.append(value)
else:
greater.append(value)
return quicksort(les) + [pivot] + quicksort(greater)
foo = [1, 7, 4, 5, 9, 14, 2, 2, 3]
print quicksort(foo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment