Skip to content

Instantly share code, notes, and snippets.

@supphawit
Last active July 5, 2018 07:59
Show Gist options
  • Save supphawit/012c5f600b053b54eb755d1527e74bbf to your computer and use it in GitHub Desktop.
Save supphawit/012c5f600b053b54eb755d1527e74bbf to your computer and use it in GitHub Desktop.
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