Created
August 13, 2013 21:49
-
-
Save horiajurcut/6226055 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
X = [9, 3, 1, 10, 3, 2, 8, 6, 4, 5, 0] | |
def merge(L, R): | |
A = [] | |
i, j = 0, 0 | |
while i < len(L) and j < len(R): | |
if L[i] < R[j]: | |
A.append(L[i]) | |
i = i + 1 | |
else: | |
A.append(R[j]) | |
j = j + 1 | |
A += L[i:] | |
A += R[j:] | |
return A | |
def merge_sort(A): | |
if len(A) <= 1: | |
return A | |
m = int(len(A) / 2) | |
L = merge_sort(A[:m]) | |
R = merge_sort(A[m:]) | |
return merge(L, R) | |
print merge_sort(X) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment