随笔分类 -  Python算法

摘要:"""插入排序的基本思想是:将列表分为2部分,左边为排序好的部分,右边为未排序的部分,循环整个列表,每次将一个待排序的记录,按其关键字大小插入到前面已经排好序的子序列中的适当位置,直到全部记录插入完成为止。"""import randomimport timedef insertion_sort(a 阅读全文
posted @ 2018-04-25 09:55 Paco_Pig 阅读(136) 评论(0) 推荐(0)
摘要:import time,randomdef sift_down(arr, node, end): root = node #print(root,2*root+1,end) while True: # 从root开始对最大堆调整 child = 2 * root +1 #left child if 阅读全文
posted @ 2018-04-25 09:54 Paco_Pig 阅读(100) 评论(0) 推荐(0)
摘要:class TreeNode(object): def __init__(self,data=0,left=0,right=0): self.data = data self.left = left self.right = right class BTree(object): def __init 阅读全文
posted @ 2018-04-25 09:53 Paco_Pig 阅读(132) 评论(0) 推荐(0)
摘要:#快速排序import randomimport timedef quick_sort(array,start,end): if start >= end: return k = array[start] left_flag = start right_flag = end while left_f 阅读全文
posted @ 2018-04-25 09:52 Paco_Pig 阅读(143) 评论(0) 推荐(0)
摘要:先理解a=123,b=321,两个互换的方法和思路,其实就是找个中间变量存放其值 >>> a=123 >>> b=321 >>> tmp=a >>> a=b >>> b=tmp >>> a,b (321, 123) li = [13,22,6,99,11] 请按照一下规则计算: 13 和 22 比较 阅读全文
posted @ 2018-04-25 09:51 Paco_Pig 阅读(139) 评论(0) 推荐(0)
摘要:import random,timedef selection_sort(array): for i in range(len(array)): smallest_index = i for j in range(i,len(array)): if array[smallest_index] > a 阅读全文
posted @ 2018-04-25 09:50 Paco_Pig 阅读(164) 评论(0) 推荐(0)