You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* implementation of Dijkstra's algorithm, returns pairs of a vertex and the minimum weight needed to get to that vertex (the starting vertex is the first added)
52
+
*
53
+
* Dijkstra's algorithm,
54
+
*
55
+
* returns pairs of a vertex and the minimum weight needed to get to that vertex,
56
+
*
57
+
* the starting vertex is the first added
58
+
*
56
59
*/
57
-
fundijkstraAlgorithm(): Map<Vertex<T>, Int> {
60
+
fundijkstraAlgorithm(): Map<T, Int> {
61
+
if (data.isEmpty()) return emptyMap()
62
+
58
63
val unvisitedVertexes = linkedMapOf<Vertex<T>, Int>()
59
64
data.keys.forEach { vertex ->
60
65
unvisitedVertexes[vertex] =Int.MAX_VALUE
61
66
}
62
67
63
-
val visitedVertexes = linkedMapOf<Vertex<T>, Int>()
68
+
val visitedVertexes = linkedMapOf<T, Int>()
64
69
var minimumCost =0
65
70
66
-
var currentVertex = unvisitedVertexes.keys.firstOrNull() ?:return visitedVertexes
71
+
var currentVertex = unvisitedVertexes.keys.first()
67
72
while(unvisitedVertexes.isNotEmpty()) {
68
73
val neighbourVertexConnections = data[currentVertex] ?: emptyList()
69
74
for (neighbourVertexConnection in neighbourVertexConnections) {
0 commit comments