def QuickSort(myList,start,end):
if start < end:
i,j = start, end
base = myList[i]
while i < j:
while (i
= base):
j = j -1
myList[i] = myList[j]
while (i
<= base):
i = i + 1
myList[j] = myList[i]
myList[i] = base
#递归前后半区
QuickSort(myList,start, i-1)
QuickSort(myList,j+1,end)
return myList
myList = [1,9,3,8,6,12,28,37,86,99,100,29,38]
print("Qucik Sort:")
QuickSort(myList,0,len(myList)-1)
print(myList)
注:上述代码的最终排序结果是在原列表上执行,思想是:将基线样本pivot sample 保存在变量base中。然后右边比base小的样本值传入base原来的位置。