快速排序
#快速排序
def quick_sort(alist , first=0 ,last=None):
if last is None:
last = len(alist) - 1
if first >= last:
return
mid_val = alist[first]
low=first
high = last
while low < high:
while low < high and alist[high] >= mid_val:
high -= 1
alist[low],alist[high] = alist[high],alist[low]
while high > low and alist[low] < mid_val:
low += 1
alist[high],alist[low] = alist[low],alist[high]
alist[low],mid_val= mid_val,alist[low]
quick_sort(alist,first,low-1)
quick_sort(alist,low+1,last)
if __name__=="__main__":
l = [23 ,54 ,12 ,8, 48,16,88,3,36]
print(l)
quick_sort(l)
print(l)