D.数据结构(快速排序)
A.快速排序
1.算法逻辑
若要对
def quick_sort(alist,first,last): if first >= last: # 递归结束条件 return high = last low = first media_data = alist[first] while low < high: while low < high and alist[high] > media_data: # 必须先从high开始 high -= 1 alist[low] = alist[high] while low < high 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)
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步