def _merge_sort(li1, li2, tmp):
if len(li1) == 0 or len(li2) == 0:
tmp.extend(li1)
tmp.extend(li2)
return tmp
else:
if li1[0] < li2[0]:
tmp.append(li1[0])
del li1[0]
else:
tmp.append(li2[0])
del li2[0]
return _merge_sort(li1,li2,tmp)
def merge_sort(li1, li2):
return _merge_sort(li1,li2,[])
print(merge_sort([1,3,5,12],[2,4,6,9,12]))
网友评论