Add doctest to dijkstra-algorithm

This commit is contained in:
lubaso 2023-10-06 23:58:26 -03:00
parent 8679c63752
commit b511783731

View File

@ -56,9 +56,9 @@ def dijkstra(graph, v, src):
Example:
>>> graph = [[0.0, 2.0, float('inf'), 1.0],
[2.0, 0.0, 4.0, float('inf')],
[float('inf'), 4.0, 0.0, 3.0],
[1.0, float('inf'), 3.0, 0.0]]
... [2.0, 0.0, 4.0, float('inf')],
... [float('inf'), 4.0, 0.0, 3.0],
... [1.0, float('inf'), 3.0, 0.0]]
>>> dijkstra(graph, 4, 0)
Vertex Distance
0 0
@ -102,4 +102,4 @@ if __name__ == "__main__":
graph[src][dst] = weight
gsrc = int(input("\nEnter shortest path source:").strip())
dijkstra(graph, V, gsrc)
dijkstra(graph, V, gsrc)