Dijkstra's Algo
Dijkstra's Algo
*;
@Override
public int compareTo(Node other) {
return Integer.compare(this.distance, other.distance);
}
}
Arrays.fill(distances, Integer.MAX_VALUE);
distances[start] = 0;
minHeap.add(new Node(start, 0));
while (!minHeap.isEmpty()) {
Node current = minHeap.poll();
int u = current.vertex;
if (visited[u]) {
continue;
}
visited[u] = true;
return distances;
}
int[][] graph = {
{0, 7, 9, 0, 0, 14},
{7, 0, 10, 15, 0, 0},
{9, 10, 0, 11, 0, 2},
{0, 15, 11, 0, 6, 0},
{0, 0, 0, 6, 0, 9},
{14, 0, 2, 0, 9, 0}
};
int startVertex = 0;
int[] distances = dijkstra(graph, startVertex);