a=[5,4,2,3,1]print(a)n=len(a)l=0r=n-1while True: if a[l]>a[r]: a[l],a[r]=a[r],a[l] r=r-1 if l==r: l=l+1 r=n-1 if l==n-1: breakprint(a)
[5, 4, 2, 3, 1][1, 2, 3, 4, 5]
本文共 263 字,大约阅读时间需要 1 分钟。
a=[5,4,2,3,1]print(a)n=len(a)l=0r=n-1while True: if a[l]>a[r]: a[l],a[r]=a[r],a[l] r=r-1 if l==r: l=l+1 r=n-1 if l==n-1: breakprint(a)
[5, 4, 2, 3, 1][1, 2, 3, 4, 5]
转载于:https://www.cnblogs.com/luoganttcc/p/10525382.html