Last active
October 3, 2015 14:54
-
-
Save multivac61/4be0963369db9ff59be0 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 quick_sort(m, sort_by): | |
def partition(m, lo, hi): | |
p = m[hi] # choose a pivot | |
i = lo | |
for j in range(lo, hi): | |
if sort_by(m[j], p): | |
m[i], m[j] = m[j], m[i] | |
i += 1 | |
m[i], m[hi] = m[hi], m[i] | |
return i | |
def _quick_sort(m, lo, hi): | |
if lo < hi: | |
p = partition(m, lo, hi) | |
_quick_sort(m, lo, p-1) | |
_quick_sort(m, p+1, hi) | |
m = list(m) # deep copy | |
_quick_sort(m, 0, len(m)-1) | |
return m |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment