Created
October 12, 2013 17:58
-
-
Save horiajurcut/6952893 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 merge_sort(seq): | |
mid = len(seq) // 2 | |
left, right = seq[:mid], seq[mid:] | |
if len(left) > 1: | |
left = merge_sort(left) | |
if len(right) > 1: | |
right = merge_sort(right) | |
res = [] | |
while left and right: | |
if left[-1] >= right[-1]: | |
res.append(left.pop) | |
else: | |
res.append(right.pop) | |
res.reverse() | |
return (left or right) + res |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment