Created
March 28, 2017 09:36
-
-
Save KIDJourney/0ec45fd79c049b21b9911b9b36b218f8 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 qsort(items, cmp=lambda x, y : x>y): | |
if not items: | |
return [] | |
mid = items[0] | |
left = [i for i in items[1:] if cmp(i, mid)] | |
right = [i for i in items[1:] if not cmp(i, mid)] | |
return qsort(left, cmp) + [mid] + qsort(right, cmp) | |
print(qsort([1,2,3,4,5])) | |
print(qsort([5,4,3,2,1], cmp=lambda x,y : x<y)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment