![](https://img-blog.csdnimg.cn/20190927151053287.png?x-oss-process=image/resize,m_fixed,h_224,w_224)
排序
快排,堆排序
伯爵er
这个作者很懒,什么都没留下…
展开
-
堆排序
如何用代码表示一个堆: 如何用数组存储一个堆: [0,1,2,3,4,5,6,7,8,9,10] 父节点: parent = (i-1)/2 两个子节点: c1 = 2i+1 c2 = 2i+2 ''' parent = (i-1)/2 c1 = 2i+1 c2 = 2i+2 ''' def swap(arr, i, j): temp = arr[i] arr[i] = arr[j] arr[j] = temp def heapify(tree, n, i): if i &g原创 2020-06-01 08:33:26 · 115 阅读 · 0 评论 -
冒泡排序
def BubbleSort(list): len_l = len(list) for i in range(len_l): exchange = False for j in range(len_l-1, i, -1): if list[j] < list[j-1]: list[j], ...原创 2020-03-26 09:42:54 · 97 阅读 · 0 评论 -
快速排序
def partition(list, s, t): temp = list[s] while s < t: while s<t and temp<=list[t]:#找到右边第一个小于temp的数,停止 t -= 1 list[s] = list[t] while s<t and te...原创 2020-03-26 09:04:43 · 116 阅读 · 0 评论