{
Int mindist, I, j, k, t=1;
for(i=1; i <=G - & gt; Vexnum; I++) {
Dist [I]=G - & gt; Arcs [start] [I];//the dist array initialization
If (G - & gt; Arcs [start] [I]!=INFINITY)
The path [I] [1]=start;
}
The path [start] [0]=1;
For (I=2; i <=G - & gt; Vexnum; I++) {//looking for various shortest path
Mindist=INFINITY;
for(j=1; j <=G - & gt; Vexnum; J++)
if(! The path [j] [0] & amp; & Dist [j]
Mindist=dist [j];
}
If (mindist==INFINITY)
return ;
The path [k] [0]=1;//to find the shortest path
for(j=1; j <=G - & gt; Vexnum; J++) {//modify path
if(! The path [j] [0] & amp; & G - & gt; Arcs [k] [j]
t=1;
While (the path [k] [t]!=0) {
The path [j] [t]=path [k] [t];
T++;
}
The path [j] [t]=k;
The path [j] [t + 1)=0.
}
}
}
for(i=1; i <=G - & gt; Vexnum; I++)
If (I==end)
break;
Printf (" % s \ n - & gt; % s the shortest route is: from % s ", the G & gt; Vex [start]. Name, G - & gt; Vex [end]. Name, G - & gt; Vex [start]. Name);
For (j=2; The path [I] [j].=0; J++) {
Printf (" - & gt; % s ", the G & gt; Vex [path [I] [j]] name);
}
Printf (" - & gt; For % d % s, distance m \ n ", the G & gt; Vex [end]. Name, dist [I]);
Printf (" \ n \ t \ \ t \ \ t t t press any key to return... ");
Getch ();
}
CodePudding user response:
Can you don't look at the code, describing how clear Dijkstra algorithm works?If you can, the code can see
If not, explain also in vain
The existing theoretical basis
CodePudding user response:
Okay, I understand this algorithm again carefullyCodePudding user response:
(1) scene description(2) algorithm description
(3) code
(4) the test pass
CodePudding user response:
Fun