Home > Back-end >  Dijkstra algorithm searching for the shortest path through the points of how to record
Dijkstra algorithm searching for the shortest path through the points of how to record

Time:10-24

After using algorithm to search the shortest path, can put a lot of points in S, how should I put the real thoughts to walk the path of the node and mark? Please god help!
For (int k=2; k<=30; After removing k++)//s vertices of other vertex number
{
if(! Final [d])
{
Int min;//the current known s vertex of the closest distance
Min=1000;
for(j=1; j<=30; J++)
{
if(! Final [j])//j vertex without through collection, in both v -s
If (D [j] {
I=j;
Min=D [j];
}
}

Final [I]=true;
Path1 [k]=I;
for(j=1; j<=30; J++)//update the current shortest path and distance
{
if(! Final [j] & amp; & (min + weight [I] [j]) & lt; D [j])//modify D [j] and [j] P
{
D [j]=min + weight [I] [j];
P=p [j] [I];
P [j] [j]=true;
}
}
}
The else
break;
}
Int a=1;
For (m=1; M<=k; M++)
If (p [d] [path1 [m]])
{
The path [+]=path1 [m].

}
What I use is the last of a for loop to limit S points, but in the end, the results showed that path is always more part of the point, how should I delete selected points in S
  • Related