File tree Expand file tree Collapse file tree 1 file changed +3
-3
lines changed
Dijkstra Algorithm/Dijkstra.playground/Sources Expand file tree Collapse file tree 1 file changed +3
-3
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ public class Dijkstra {
19
19
var currentVertex : Vertex ? = startVertex
20
20
while let vertex = currentVertex {
21
21
currentVertices. remove ( vertex)
22
- let filteredNeighbors = vertex. neighbors. filter { totalVertices . contains ( $0. 0 ) }
22
+ let filteredNeighbors = vertex. neighbors. filter { currentVertices . contains ( $0. 0 ) }
23
23
for neighbor in filteredNeighbors {
24
24
let neighborVertex = neighbor. 0
25
25
let weight = neighbor. 1
@@ -31,11 +31,11 @@ public class Dijkstra {
31
31
neighborVertex. pathVerticesFromStart. append ( neighborVertex)
32
32
}
33
33
}
34
- if totalVertices . isEmpty {
34
+ if currentVertices . isEmpty {
35
35
currentVertex = nil
36
36
break
37
37
}
38
- currentVertex = totalVertices . min { $0. pathLengthFromStart < $1. pathLengthFromStart }
38
+ currentVertex = currentVertices . min { $0. pathLengthFromStart < $1. pathLengthFromStart }
39
39
}
40
40
}
41
41
}
You can’t perform that action at this time.
0 commit comments