MCPcopy Create free account
hub / github.com/loiane/javascript-datastructures-algorithms / minDistance

Function minDistance

src/13-graph/dijkstra.ts:5–15  ·  view source on GitHub ↗
(dist: number[], visited: boolean[])

Source from the content-addressed store, hash-verified

3const INF = Number.MAX_SAFE_INTEGER; // Infinity
4
5const minDistance = (dist: number[], visited: boolean[]): number => {
6 let min = INF;
7 let minIndex = -1;
8 for (let v = 0; v < dist.length; v++) {
9 if (visited[v] === false && dist[v] <= min) {
10 min = dist[v];
11 minIndex = v;
12 }
13 }
14 return minIndex;
15};
16
17/**
18 * Runs Dijkstra's shortest-path algorithm on an adjacency-matrix graph.

Callers 1

dijkstraFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected