Created
July 12, 2011 13:04
-
-
Save samrat/1077935 to your computer and use it in GitHub Desktop.
Crude implementation of Quicksort algorithm in Python.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def quicksort(list): | |
if len(list) <= 1: return list | |
pivot = list[0] | |
great = [] | |
less = [] | |
for item in list[1:]: | |
if item>=pivot: | |
great.append(item) | |
elif item<pivot: | |
less.append(item) | |
return quicksort(less)+[pivot]+quicksort(great) | |
#test | |
print quicksort([45,99,1,-22,7,3,294,10,36]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment