D.数据结构(快速排序)
2021-03-14 22:32
标签:必须 开始 条件 快速 and pre rgba 数据 last 1.算法逻辑 若要对 D.数据结构(快速排序) 标签:必须 开始 条件 快速 and pre rgba 数据 last 原文地址:https://www.cnblogs.com/zhaojiayu/p/14014543.htmlA.快速排序
def quick_sort(alist,first,last):
if first >= last:
# 递归结束条件
return
high = last
low = first
media_data = alist[first]
while low high:
while low and alist[high] > media_data:
# 必须先从high开始
high -= 1
alist[low] = alist[high]
while low and alist[low] media_data:
low += 1
alist[high] = alist[low]
alist[low] = media_data
quick_sort(alist, first, low-1)
quick_sort(alist, low+1, last)
if __name__ == "__main__":
li = [24, 12, 56, 34, 78, 25, 94, 77]
quick_sort(li, 0, len(li)-1)
print(li)