問題描述:Dijkstra算法的驗證?
輸入描述:無?
輸出描述:某一頂點到其他各點最短路徑?
用到了graph.h?
*/???
#include???
#include???
#include?"graph.h"??
#define?MaxSize?100??
void?Ppath(int?path[],int?i,int?v)??//前向遞歸查找路徑上的頂點??
{??
int?k;??
k=path[i];??
if?(k==v)??return;??????????//找到了起點則返回??
Ppath(path,k,v);????????????//找頂點k的前一個頂點??
printf("%d,",k);????????????//輸出頂點k??
}??
void?Dispath(int?dist[],int?path[],int?s[],int?n,int?v)??
{??
int?i;??
for?(i=0;?i
if?(s[i]==1)??
{??
printf("??從%d到%d的最短路徑長度為:%d\t路徑為:",v,i,dist[i]);??
printf("%d,",v);????//輸出路徑上的起點??
Ppath(path,i,v);????//輸出路徑上的中間點??
printf("%d\n",i);???//輸出路徑上的終點??
}??
else??printf("從%d到%d不存在路徑\n",v,i);??
}??
void?Dijkstra(MGraph?g,int?v)??
{??
int?dist[MAXV],path[MAXV];??
int?s[MAXV];??
int?mindis,i,j,u;??
for?(i=0;?i
{??
dist[i]=g.edges[v][i];??????//距離初始化??
s[i]=0;?????????????????????//s[]置空??
評論
查看更多