插入排序
def insrt_sort(aimlist): n=len(aimlist) for cur in range(1,n): i=cur while i>0: if aimlist[i]<aimlist[i-1]: aimlist[i],aimlist[i-1]=aimlist[i-1],aimlist[i] i-=1 else: break return aimlist list=[4,6,2,7,1] print(insrt_sort(list))
希尔排序
def shell_sort(aimlist): n=len(aimlist) gap=n//2 while gap>=1: for cur in range(gap,n): i=cur while i>0: if aimlist[i]<aimlist[i-gap]: aimlist[i],aimlist[i-gap]=aimlist[i-gap],aimlist[i] i-=gap else: break gap=gap//2 return aimlist list=[4,6,2,4,2,7,1] print(shell_sort(list))
标签:aimlist,shell,cur,05,Python,插入排序,gap,while From: https://www.cnblogs.com/yyyjw/p/18024891