#include
#include
#define ok 1
#define error -1
#define max_vertex_num 12
#define network_infinity 32767
typedef struct arccell adjmatrix[max_vertex_num][max_vertex_num];
typedef struct amgraph;
int locatevex( amgraph g,int name ) //返回頂點標號為name的頂點,在陣列vexs中的位置
int createdn( amgraph *g ) //建立有向網
/*初始化鄰接矩陣*/
for(i=0;i< g->vexnum ;i++)
for(j=0;j< g->vexnum ;j++)
/* 構造鄰接矩陣 */
for(k = 0;k < g -> arcnum;k ++)
while((v1<0)||(v1>g->vexnum));
printf(" 弧 頭:");dowhile((v2<0)||(v2>g->vexnum));
printf(" 權 重:");scanf("%d",&w);
i = locatevex(*g,v1); j = locatevex(*g,v2);
(g->arcs)[i][j].adj = w;
printf("/n");
}return ok;
}void shortestpath_floyd(amgraph *g,int p[max_vertex_num][max_vertex_num][max_vertex_num], int d[max_vertex_num][max_vertex_num])
//if
}//for
for(u = 0; u < g->vexnum; u ++)
for(v = 0; v < g->vexnum; v ++)
for(w = 0; w < g->vexnum; w ++)
if(d[v][u] + d[u][w] < d[v][w])
}/**************************===主函式main()***********************************=*/
int main( void )
printf("/n/n各個頂點之間的最短距離矩陣:/n");
shortestpath_floyd(&g, pathmatrix, distancmatrix);
for(i = 0;i < g.vexnum;i ++)
printf("/n/n");
for(i = 0;i < g.vexnum;i ++)
printf("/n");
}getch();
return 0;
求每一對頂點之間的最短距離
求每一對頂點之間的最短距離 鄰接矩陣 依次加入各個頂點 include include using namespace std define maxsize 32 string getstr string s,string s2 return str class graph bool init vo...
弗洛伊德演算法求每一對頂點之間的最短路徑
include define vertex num 3 define infinity 10000 define true 1 define false 0 typedef struct graph graph void shortestpath graph g,int p vertex num v...
弗洛伊德演算法(每一對頂點之間的最短路徑)
for int i 1 i vtxnum i for int j 1 j vtxnum j for k 1 k vtxnum k 中間點 for int i 1 i vtxnum i for int j 1 j vtxnum j if dist i k dist k j dist i j dist是...