参考代码:
def quick_sort(q, l, r):
if l>=r:
return
i, j = l-1, r+1
x = q[(l+r)//2]
while i < j:
while True:
i+=1
if q[i]>=x:
break
while True:
j-=1
if q[j]<=x:
break
if i < j:
q[i], q[j] = q[j], q[i]
quick_sort(q, l, j)
quick_sort(q, j+1, r)
if __name__ == "__main__":
n=int(input())
li=list(map(int,input().split()))
l=0
r=n-1
quick_sort(li,l,r)
for i in li:
print(i,end=' ')
0.0分
3 人评分