python 快速排序
a=[5,4,2,3,1]
print(a)
n=len(a)
l=0
r=n-1
while 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:
break
print(a)
[5, 4, 2, 3, 1]
[1, 2, 3, 4, 5]
a=[5,4,2,3,1]
print(a)
n=len(a)
l=0
r=n-1
while 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:
break
print(a)
[5, 4, 2, 3, 1]
[1, 2, 3, 4, 5]