Created
December 19, 2016 06:02
-
-
Save EmadMokhtar/ce7303533ca59bddd0525e4f671db1ad to your computer and use it in GitHub Desktop.
Python Algorithms
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 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