|
|
|
@ -262,6 +262,7 @@ void ShortestMoney(MatGrath &G,int v,int w)//求花费最少的路径
|
|
|
|
|
算法floyd
|
|
|
|
|
|
|
|
|
|
如以下代码,采用迪杰斯特拉算法实现求取路径最短值
|
|
|
|
|
```
|
|
|
|
|
int Ppath2(MatGrath &G,int path[],int i,int v) //前向递归查找路径上的顶点
|
|
|
|
|
{
|
|
|
|
|
int k;
|
|
|
|
@ -330,8 +331,9 @@ int Ppath1(MatGrath &G,int path[][MAXV],int v,int w) //前向递归查找
|
|
|
|
|
printf("%s->",G.vexs[k].sight);
|
|
|
|
|
Ppath1(G,path,k,w); //找顶点k的前一个顶点j
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
如下采用floyd算法求给出的两点之间的最少费用
|
|
|
|
|
```
|
|
|
|
|
void ShortestMoney(MatGrath &G,int v,int w)//求花费最少的路径
|
|
|
|
|
{
|
|
|
|
|
int A[MAXV][MAXV],path[MAXV][MAXV];
|
|
|
|
@ -369,7 +371,7 @@ void ShortestMoney(MatGrath &G,int v,int w)//求花费最少的路径
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|