def patition(li,left,right):
tep = li[left]
while left < right and li[right] >= tep:
right -= 1
li[left] = li[right]
while left < right and li[left] <= tep:
left += 1
li[right] = li[left]
li[left] = tep #此时左右两个游标在一个位置,所以用left,right都可以
return left
def quick_sort(li,left,right):
if left < right:
mid = patition(li,left,right)
quick_sort(li,left,mid-1)
quick_sort(li,mid+1,right)
lee = [random.randint(0,100) for _ in range(10)]
print("排序前: ",lee)
quick_sort(lee,0,len(lee)-1
print("排序后: ",lee)