public class Dijkstra {private static int N = 1000;private static int[][] Graph = {{0, 1, 5, n, N, N, N, N, n}, {1, 0, 3, 7, 5, N, N, N, n},{5, 3, 0, N, 1, 7, n, N, n}, {n, 7, N, 0, 2, N, 3, N, n}, {n, 5, 1, 2, 0, 3, 6, 9, n},{N, N, 7, N, 3, 0, N, 5, n}, {n, N, N, 3, 6, N, 0, 2, 7}, {n, n, N, N, 9, 5, 2, 0, 4},{N, N, N, N, N, N, 7, 4, 0}};p ubli c static void Main (string[] args) {Dijkstra (0, Graph);} /** * Dijkstra Shortest path. * That is, the shortest path to each of the other nodes in the graph "Node vs". * @param vs Start Node * @param graph */public static void Dijkstra (int vs, int[][] Graph) {int NUM = graph[0].length;//Precursor section count Group int[] Prenode = new int[num];//shortest distance array int[] Mindist = new int[num];//Whether the node has found the shortest path boolean[] Find = new Boolean[num];int Vnear = 0;for (int i = 0; i < mindist.length; i++) {prenode[i] = i;mindist[i] = Graph[vs][i];find[i] = false;} Find[vs] = true;for (int v = 1; v < graph.length; v++) {//Each loop evaluates distance vs nearest node Vnear and shortest distance minint min = n;for (int j = 0; J &L T Graph.length; J + +) {if (!find[j] && mindist[J] < min) {min = Mindist[j];vnear = j;}} Find[vnear] = true;//modifies vs to all other nodes based on vnear and distance for (int k = 0; k < graph.length; k++) {if (!find[k] && (min + Graph[vnear][k]) < Mindist[k]) {prenode[k] = vnear;mindist[k] = min + graph[vnear][k];}}} for (int i = 0; i < NUM; i++) {System.out.println ("V" + vs + "... v" + prenode[i] + "->v" + i + ", s=" + mindist[i]); }}
Java implementation of Dijkstra algorithm