Last active
July 5, 2018 07:59
-
-
Save supphawit/012c5f600b053b54eb755d1527e74bbf to your computer and use it in GitHub Desktop.
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(alist,low,high): | |
if low < high: | |
pivot = partition(alist,low,high) | |
quickSort(alist,low,pivot-1) | |
quickSort(alist,pivot+1,high) | |
return alist | |
def partition(alist,low,high): | |
i = -1 | |
pivot = alist[high] | |
for j in range(0,len(alist)): | |
if alist[j] <= pivot: | |
i += 1 | |
# swap | |
alist[i],alist[j] = alist[j],alist[i] | |
# initial new pivot | |
new_pivot = alist.index(pivot) | |
return new_pivot | |
listNumber = [10,80,30,90,40,50,70] | |
lengthList = len(listNumber) | |
print (quickSort(listNumber,0,lengthList-1)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment