标签:sts print pre app list append 归并排序 middle merge
def merge(a, b): c = [] h = j = 0 while j < len(a) and h < len(b): if a[j] < b[h]: c.append(a[j]) j += 1 else: c.append(b[h]) h += 1 if j == len(a): for i in b[h:]: c.append(i) else: for i in a[j:]: c.append(i) return c def merge_sort(lists): if len(lists) <= 1: return lists middle = len(lists) // 2 left = merge_sort(lists[:middle]) right = merge_sort(lists[middle:]) return merge(left, right) a = [4, 7, 7, 1, 2, 9] print(merge_sort(a))
标签:sts print pre app list append 归并排序 middle merge
原文地址:https://www.cnblogs.com/hooo-1102/p/12028389.html