2022年4月10日
摘要: import heapqa = [1,3,2,7,5,4,9,0]b= []for i in a: heapq.heappush(b,i)c= []for k in range(len(b)): c.append(heapq.heappop(b))print(c)result:[0, 1, 2, 3 阅读全文
posted @ 2022-04-10 18:09 dale、 阅读(36) 评论(0) 推荐(0)
摘要: 一、1.1a = [2,4,1,3,6,1,4]heapq.heappush(a,3)print(a)heapq.heappush(a,5)print(a)heapq.heappush(a,1)如果原列表有值,那么新增加的值不能自动与原列表的值构成小顶堆。result: [2, 4, 1, 3, 6 阅读全文
posted @ 2022-04-10 17:54 dale、 阅读(147) 评论(0) 推荐(0)