Last active
August 29, 2015 14:25
-
-
Save ShinJJang/1dcd06bc4a7cd39a7e8b to your computer and use it in GitHub Desktop.
fail merge sort
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(array1, array2): | |
a_index = 0 | |
b_index = 0 | |
result = [] | |
# wrong while condition | |
while a_index < len(array1) and b_index < len(array2): | |
if array1[a_index] > array2[b_index]: | |
result.append(array2[b_index]) | |
b_index+=1 | |
else: | |
result.append(array1[a_index]) | |
a_index+=1 | |
return result | |
a = [1, 2, 5] | |
b = [3, 4, 6] | |
print(merge(a, b)) | |
# [1, 2, 3, 4, 5] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What is wrong: