快速排序
# 内部排序
def partition(arr,left,right):
p = arr[left]
while left < right:
while left < right and arr[right]>p:
right -= 1
arr[left],arr[right] = arr[right],arr[left]
while left < right and arr[left]<=p:
left +=1
arr[left],arr[right] = arr[right],arr[left]
return left
# 快排框架
def quick(arr,left,right):
if left < right:
pi = partition(arr,left,right)
quick(arr,left,pi-1)
quick(arr,pi+1,right)
return arr
if __name__ == '__main__':
L = [1,3,4,3,2,23,4,1,2]
print(quick(L,0,len(L)-1))