def quick_sort(left, right, data):
if left < right:
mid = find_mid(left, right, data)
quick_sort(left, mid-1, data)
quick_sort(mid+1, right, data)
return data
def find_mid(left, right, data):
mid = data[left]
while left < right:
# 左边比中间位小
while left < right and data[right] > mid:
right = right - 1
data[left] = data[right]
# 右边比中间位大
while left < right and data[left] < mid:
left = left + 1
data[right] = data[left]
# 确认中间位
data[left] = mid
return left
if __name__ == '__main__':
L = [5, 9, 1, 11, 6, 7, 2, 4]
print(quick_sort(0, len(L)-1, L))