具体算法参考:https://zhuanlan.zhihu.com/p/93129029
代码:
#!/usr/bin/python
# -*- coding: UTF-8 -*-
def QuickSort(a, low, high):
i = low
j = high
if (i < j):
temp = a[i]
while (i != j):
while (j > i and a[j] >= temp):
j -= 1
a[i] = a[j]
while (i < j and a[i] <= temp):
i += 1
a[j] = a[i]
a[i] = temp
QuickSort(a, low, i-1)
QuickSort(a, i+1, high)
return a
if __name__ == "__main__":
a = [10, 2, 3, 19, 5, 4, 20, 6, 9, 30, 1, 1]
low = 0
high = len(a) - 1
sorted_a = QuickSort(a, low, high)
print(sorted_a)