Skip to content

Commit 0a813ba

Browse files
author
Taras Nikulin
committed
Code improvements
1 parent 3e301e8 commit 0a813ba

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Dijkstra Algorithm/Dijkstra.playground/Sources/Dijkstra.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,12 @@ public class Dijkstra {
1313

1414
public func findShortestPaths(from startVertex: Vertex) {
1515
clearCache()
16+
var currentVertices = self.totalVertices
1617
startVertex.pathLengthFromStart = 0
1718
startVertex.pathVerticesFromStart.append(startVertex)
1819
var currentVertex: Vertex? = startVertex
1920
while let vertex = currentVertex {
20-
totalVertices.remove(vertex)
21+
currentVertices.remove(vertex)
2122
let filteredNeighbors = vertex.neighbors.filter { totalVertices.contains($0.0) }
2223
for neighbor in filteredNeighbors {
2324
let neighborVertex = neighbor.0

0 commit comments

Comments
 (0)