摘要:
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 阅读全文
摘要:
""" 功能:实现对有序的多个数组整体排序,获取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 ... 阅读全文