Home > Back-end >  YanWeiMin in the data structure and a bit of multi-point dijkstra algorithm, I write up is almost in
YanWeiMin in the data structure and a bit of multi-point dijkstra algorithm, I write up is almost in

Time:10-04

The shortest path, as shown in the figure 1 to 4 should be 134, running results showed that 124

CodePudding user response:

#include #include # define MAX 100 # define INFINITY 65535 typedef struct GNode {int Nv, Ne; Int G/MAX (MAX); } * MGraph; MGraph CreateGraph () {MGraph Graph=(MGraph) malloc (sizeof (GNode)); Int I, j, k, l; Printf (" please enter the number of vertices and the number of edges "); The scanf (" % d % d ", & amp; Graph - & gt; Nv, & amp; Graph - & gt; Ne); for(i=1; i<=Graph - & gt; Nv. I++) for (j=1; j<=Graph - & gt; Nv. J++) Graph - & gt; G [I] [j]=INFINITY; For (l=1; L<=Graph - & gt; Ne. L++) {printf (" please enter the article % d edge ", l); The scanf (" % d % d % d ", & amp; I, & amp; J., & amp; K); Graph - & gt; G [I] [j]=k; } return Graph; } typedef int PathMatrix [MAX] [MAX]; Typedef int Weight (MAX); Bool final (MAX); Void shortpath (MGraph Graph, int where v0, Weight & amp; D, PathMatrix & amp; The Path) {int I, j, v, w, min. For (n=1; V<=Graph - & gt; Nv. V++) {D [v]=Graph - & gt; G [where v0] [v]; Final [v]=false; For (w=1; W<=Graph - & gt; Nv. W++) {Path [w] [v]=false; }//initializes the if (! Final [v] & amp; & D [v] CodePudding user response:

Anyone bosses to answer it, put the source to the compiler can severely, bosses should have studied, the structure of the figure dijkstra algorithm
  • Related