Home > Back-end >  Have a great god can give help me speak the Dijkstra algorithm under the code
Have a great god can give help me speak the Dijkstra algorithm under the code

Time:10-11

Void Dijkstra (AdjMatrix * G, int start, int the end, int dist [], int the path [] [MAXVEX])
{
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] K=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] Dist [j]=dist [k] + 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 carefully

CodePudding user response:

(1) scene description
(2) algorithm description
(3) code
(4) the test pass

CodePudding user response:

Fun
reference 1 floor 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

This to the existing theory of

Monophyletic actually I understand, I don't know much about this behind this
Dist [j]=dist [k] + 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.
Don't know what t is

CodePudding user response:

The
reference 3 floor proorck2019 response:
(1) scene description
(2) algorithm description
(3) code
(4) the test pass

Is to achieve input starting point and end point, to find the shortest path
  • Related