python 归并排序

两个列表,合并成一个有序列表

lst1 = [1, 3, 7, 9, 12]
lst2 = [4, 8, 9, 13]
lst1 = [1, 3, 7, 9, 12]
lst2 = [4, 8, 9, 13]
lst = []
i = 0
j = 0
while i < len(lst1) and j <len(lst2) :
    if lst1[i] < lst2[j] :
        lst.append(lst1[i])
        i += 1
    else :
        lst.append(lst2[j])
        j += 1
if j ==len(lst1) :
    for i in  lst2[j:] :
        lst.append(i)
else :
    for i in lst1[i:] :
        lst.append(j)

 

posted @ 2018-07-23 16:23  北寒-  阅读(126)  评论(0编辑  收藏  举报