def Quick_sort(alist,start,end):#开始结束下标
#快速排序法
if start>=end:
return alist
low = start
high = end
base = alist[low]
while low<high:
#high左移
while low<high and alist[high]>=base:
high -= 1#下标往前移动
alist[low] = alist[high]
while low<high and alist[low]<base:
low += 1
alist[high] = alist[low]
#循环退出时,low=high
alist[high] = base
Quick_sort(alist,start,low-1)
Quick_sort(alist,low+1,end)
alist = [7,1,56,12,3,9,11]
n = len(alist)
Quick_sort(alist,0,n-1)
print(alist)
时间复杂度:
最优时间复杂度:O(nlogn)
最坏时间复杂度:O(n**2)
稳定性:不稳定