Home > Back-end >  The c language
The c language

Time:09-22

Void Floyd Mgraph (c)//with Freud thought for the shortest path
{
Int A [11] [11], the path [11] [11], apath [11].//apath for storing the shortest path in the middle of the vertex and its number
Int I, j, k, a, b, m, s, d;
for(i=0; ifor(j=0; j{A [I] [j]=c.a. RCS [j]. [I] adj.
If (I.=j& & C.a. RCS [I] [j]. Journal of adjThe path [I] [j]=I;//I to j has
The else
The path [I] [j]=1;//I to j no side
}
For (k=0; K{the for (I=0; ifor(j=0; jIf (A [I] [j] & gt; A [I] [k] + [k] [j] A)
{
A [I] [j]=[I] A [k] + [k] A [j];//modify the shortest path length I to j
The path [I] [j]=path [k] [j];
}
}
Printf (" \ n please enter the starting point (spots number) : ");//the code to output the shortest path
The scanf (" % d ", & amp; a); printf("\n");
Printf (" please enter the destination (spots number) : ");
The scanf (" % d ", & amp; B); printf("\n");
If (a==b)
Printf (" the same starting point and destination. \ n \ n path to 0, \ n ");
{if (A [A] [b]!=INF& & a! If a=b)//path between points a and b
{printf (" from % d to % d path for: ", a, b);
M=path [a] [b];
D=0; Apath [d]=b; Add the finish//path
While (m!=1 & amp; & m!//path=a) adding intermediate point
{d++; Apath [d]=m;
M=path [a] [m].
}
D++; Apath [d]=a; Add starting point//path
Printf (" % s (% d) ", apath [d], c. exs [a]. Name);//output start
For (s=d - 1; S>=0; S -)//in the middle of the vertex output path
Printf (" -- -- & gt; (% d) % s ", apath [s], c. exs [apath [s]]. Name);
Printf (" \ n \ n path length is: % d \ n \ n ", [A] [b] A);//output vertex and the length of the shortest path between
}
}
}

Freud algorithm, if the starting point and destination, there are two or more paths with length equal to, how to output at the same time??????? Solving,

CodePudding user response:

http://www.cnblogs.com/Braveliu/archive/2013/12/05/3459768.html
  • Related