摘要: def dijkstra(graph, from_node, to_node): q, seen = [(0, from_node, [])], set() while q: cost, node, path = heappop(q) seen.add(node) path = path+[node] if node == to_node: return cost,path for adj_nod 阅读全文
posted @ 2019-09-20 14:42 bonelee 阅读(1338) 评论(2) 推荐(0) 编辑
摘要: """ 功能:实现对有序的多个数组整体排序,获取top k个最小元素 """ from heapq import * def heap_sort(arr, top_k): q = [] for i in range(len(arr)): heappush(q, (arr[i][0], i, 0)) result = [] for k in ... 阅读全文
posted @ 2019-09-20 12:08 bonelee 阅读(369) 评论(0) 推荐(0) 编辑