![这里写图片描述](https://img-blog.csdn.net/20180207101954070?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvYmluZ294dWJpbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast&x-oss-process=image/resize,w_1400/format,webp)
__author__ = 'Alex Li'
def quick_sort(array,left,right):
'''
:param array:
:param left: 列表的第一个索引
:param right: 列表最后一个元素的索引
:return:
'''
if left >=right:
return
low = left
high = right
key = array[low]
while low < high:
while low < high and array[high] > key:
high -= 1
array[low] = array[high]
array[high] = key
while low < high and array[low] <= key :
low += 1
array[high] = array[low]
array[low] = key
quick_sort(array,left,low-1)
quick_sort(array,low+1, right)
if __name__ == '__main__':
array = [96,14,10,9,6,99,16,5,1,3,2,4,1,13,26,18,2,45,34,23,1,7,3,22,19,2]
print("before sort:", array)
quick_sort(array,0,len(array)-1)
print("-------final -------")
print(array)