Skip to content

Instantly share code, notes, and snippets.

@ShinJJang
Last active August 29, 2015 14:25
Show Gist options
  • Save ShinJJang/733715e42231c99e10b1 to your computer and use it in GitHub Desktop.
Save ShinJJang/733715e42231c99e10b1 to your computer and use it in GitHub Desktop.
working merge sort
def merge(array1, array2):
a_index = 0
b_index = 0
result = []
while a_index < len(array1) or b_index < len(array2):
if a_index >= len(array1) or array1[a_index] > array2[b_index]:
result.append(array2[b_index])
b_index+=1
elif b_index >= len(array2) or array1[a_index] <= array2[b_index]:
result.append(array1[a_index])
a_index+=1
return result
a = [1, 2, 5]
b = [3, 4, 6]
print(merge(a, b))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment