Skip to content

Instantly share code, notes, and snippets.

@buranmert
Created May 31, 2015 10:03
Show Gist options
  • Save buranmert/4dbd02233f62040f3e9d to your computer and use it in GitHub Desktop.
Save buranmert/4dbd02233f62040f3e9d to your computer and use it in GitHub Desktop.
Quicksort python
def quicksort(array):
if len(array) <= 1:
return array
less = []
more = []
equal = []
pivot = array[len(array)/2]
for x in array:
if x < pivot:
less.append(x)
elif x > pivot:
more.append(x)
else:
equal.append(x)
return quicksort(less) + quicksort(equal) + quicksort(more)
if __name__ == "__main__":
data = [1, 10, 50, 14, 1200, 0541, 65434, -1, -2341421, 132412, 1214,124,142124,125, 124, 123, 122, 121]
print quicksort(data)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment