最短路径算法 - 迪杰斯特拉算法伪代码
作者:野牛程序员:2023-05-27 14:27:52其他阅读 2688
最短路径算法 - 迪杰斯特拉算法(Dijkstra's Algorithm):
function dijkstra(graph, start): distances = new Map() previous = new Map() unvisited = graph.getNodes() distances[start] = 0 while unvisited is not empty: current = node with the smallest distance in distances unvisited.remove(current) for neighbor in graph.getNeighbors(current): distance = distances[current] + graph.getWeight(current, neighbor) if distance < distances[neighbor]: distances[neighbor] = distance previous[neighbor] = current return distances, previous
野牛程序员教少儿编程与信息学奥赛-微信|电话:15892516892
- 上一篇:二分查找伪代码
- 下一篇:最小生成树算法 - 克鲁斯卡尔算法伪代码