Created
August 28, 2012 21:48
-
-
Save vshivam/3504637 to your computer and use it in GitHub Desktop.
Quick Sort Simple
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(arr): | |
len_arr = len(arr) | |
if(len_arr<2): | |
return arr | |
else: | |
lower = [] | |
upper = [] | |
pivot = [] | |
pivot.append(arr[len_arr-1]) | |
for i in arr: | |
if(i < arr[len_arr-1]): | |
lower.append(i) | |
elif(i > arr[len_arr-1]): | |
upper.append(i) | |
elif(i == arr[len_arr-1]): | |
pivot.append(i) | |
return quicksort(lower)+pivot+quicksort(upper) | |
print quicksort([1,2,1,5,7,3,6,8,10,33,12,9]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment