<pre name= "code" class= "java" >/* * sets a U-set, including the minimum path length and the previous node * V-u collection to indicate that no adjustment has been made * The v-u set is gradually increased by U. and adjust the minimum path * */public class Dijkstra {private static int MAX = 10000;public static void Dijkstra (Graphmatrix grap, Path dist[ ]) {//Initialize V0init (grap,dist); int n = dist.length;int minw = max;int mv = 0;for (int i=1;i<n;i++) {int j;//find and V0 distance recent vertices mvfor (j=1;j<n;j++) {if (grap.arcs[j][j]==0 && dist[j].length<max) {mv=j;minw = Dist[j].length;}} if (mv = = 0) break;grap.arcs[mv][mv]=1; Add vertex mv to u//adjust v-u known shortest path for (j=1;j<n;j++) {if (grap.arcs[j][j]==0 && dist[j].length > Dist[mv].length + Grap.arcs[mv][j]) {dist[j].length = Dist[mv].length + grap.arcs[mv][j];d ist[j].pre = mv;}}}
Dijkstra Algorithm---Java implementation