python算法实践7-归并排序

def MergeSort(mylist, low, mid, high): i = low j = mid + 1 tmp = [] while i <= mid and j <= high: if mylist[i] <= mylist[j]: tmp.append(mylist[i]) i = i + 1 else: tmp.append(mylist[j]) j = j + 1 while i <= mid: tmp.append(mylist[i]) i = i + 1 while j <= high: tmp.append(mylist[j]) j = j + 1 for k in range(low, high): mylist[k] = tmp[k] mylist0 = [1, 3, 5, 7, 9, 11, 6, 8, 66, 88, 100] MergeSort(mylist0, 0, 5, len(mylist0) - 1) print(mylist0)

你可能感兴趣的:(算法,python)