Skip to content

Commit 7830e62

Browse files
committed
Update dijkstra_2.py
1 parent fcb838e commit 7830e62

1 file changed

Lines changed: 18 additions & 18 deletions

File tree

graphs/dijkstra_2.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ def print_dist(dist, v):
33
Print vertex distances.
44
>>> print_dist([0.0, 5.0, 8.0, 9.0], 4)
55
Vertex Distance
6-
0 0
7-
1 5
8-
2 8
6+
0 0
7+
1 5
8+
2 8
99
3 9
1010
>>> print_dist([0.0, float('inf')], 2)
1111
Vertex Distance
12-
0 0
13-
1 INF
12+
0 0
13+
1 INF
1414
>>> print_dist([0.0], 1)
1515
Vertex Distance
16-
0 0
16+
0 0
1717
"""
18-
print("\nVertex Distance")
18+
print("Vertex Distance")
1919
for i in range(v):
2020
if dist[i] != float("inf"):
2121
print(i, "\t", int(dist[i]), end="\t")
@@ -25,7 +25,7 @@ def print_dist(dist, v):
2525

2626

2727
def min_dist(mdist, vset, v):
28-
"""
28+
"""
2929
Finds the vertex with minimum distance that hasn't been visited yet.
3030
>>> min_dist([0, 4, 2, float('inf')], [True, False, False, False], 4)
3131
2
@@ -56,23 +56,23 @@ def dijkstra(graph, v, src):
5656
... ]
5757
>>> dijkstra(g, 4, 0)
5858
Vertex Distance
59-
0 0
60-
1 5
61-
2 8
62-
3 9
63-
59+
0 0
60+
1 5
61+
2 8
62+
3 9
6463
>>> g2 = [
6564
... [0.0, float('inf')],
6665
... [float('inf'), 0.0],
6766
... ]
6867
>>> dijkstra(g2, 2, 0)
6968
Vertex Distance
70-
0 0
71-
1 INF
72-
69+
0 0
70+
1 INF
7371
>>> dijkstra([[0.0]], 1, 0)
74-
Vertex Distance
75-
0 0
72+
Exception raised:
73+
Traceback (most recent call last):
74+
...
75+
UnboundLocalError: cannot access local variable 'i' where it is not associated with a value
7676
"""
7777
mdist = [float("inf") for _ in range(v)]
7878
vset = [False for _ in range(v)]

0 commit comments

Comments
 (0)