Skip to content

Instantly share code, notes, and snippets.

@EmadMokhtar
Created December 19, 2016 06:02
Show Gist options
  • Save EmadMokhtar/ce7303533ca59bddd0525e4f671db1ad to your computer and use it in GitHub Desktop.
Save EmadMokhtar/ce7303533ca59bddd0525e4f671db1ad to your computer and use it in GitHub Desktop.
Python Algorithms
def partition(alist, start, end):
pos = start
for i in range(start, end):
if alist[i] < alist[end]:
alist[i], alist[pos] = alist[pos], alist[i]
pos += 1
alist[pos], alist[end] = alist[end], alist[pos]
return pos
def quicksort(alist, start, end):
if start < end:
pos = partition(alist, start, end)
quicksort(alist, start, pos - 1)
quicksort(alist, pos + 1, end)
return alist
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment