# 取pivot 将比pivot大的放在piovt右边 比piovt小的放在piovt右边
def get_mid(a, left, right):
pivot = a[left]
while right > left:
#寻找右边比piovt小的数
while a[right] > pivot and right > left:
right -= 1
a[left] = a[right]
# 寻找左边比piovt小的数
while a[left] < pivot and right > left:
left += 1
a[right] = a[left]
mid = left
a[mid] = pivot
#得到pivot的地址
return mid
def quick_sort(a, left, right):
if left < right:
mid = get_mid(a, left, right)
#将pivot左边的数组做快速排序
quick_sort(a, left, mid - 1)
# 将pivot右边的数组做快速排序
quick_sort(a, mid + 1, right)
def main():
arr = [6, 5, 4, 3, 2, 1]
quick_sort(arr, 0, len(arr) - 1)
print(arr)
main()