python算法实践2-shell排序

#shell排序 def ShellPass(mylist, d): size = len(mylist) i = d while i < size: if mylist[i] < mylist[i - d]: tmp = mylist[i] j = i - d mylist[j + d] = mylist[j] j = j - d while j >= 0 and mylist[j] > tmp: mylist[j + d] = mylist[j] j = j - d mylist[j + d] = tmp i = i + d def ShellSort(mylist): n = len(mylist) while n > 1: n = n // 3 + 1 ShellPass(mylist, n) mylist0 = [12, 11, 13, 1, 2, 4, 3, 77, 44] ShellSort(mylist0) print(mylist0)

 

 

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