|
|
@ -65,7 +65,54 @@ struct list {
|
|
|
|
```
|
|
|
|
```
|
|
|
|
代码:
|
|
|
|
代码:
|
|
|
|
```
|
|
|
|
```
|
|
|
|
|
|
|
|
int num2=0;
|
|
|
|
|
|
|
|
void Dijkstra(int v1,int v2){
|
|
|
|
|
|
|
|
int dist[MAX],s[MAX],path[MAX];//s判断v1是否已经判断最短路径,path前驱
|
|
|
|
|
|
|
|
int min,i,j,u,pre;
|
|
|
|
|
|
|
|
for(i=0;i<nm.n;i++){
|
|
|
|
|
|
|
|
dist[i]=cont[v1][i];
|
|
|
|
|
|
|
|
s[i]=0;
|
|
|
|
|
|
|
|
if(cont[v1][i]<MAX) path[i]=v1;
|
|
|
|
|
|
|
|
else path[i]=-1;
|
|
|
|
|
|
|
|
}//初始化操作
|
|
|
|
|
|
|
|
s[v1]=1;
|
|
|
|
|
|
|
|
path[v1]=0;
|
|
|
|
|
|
|
|
for(i=0;i<nm.n;i++){
|
|
|
|
|
|
|
|
min=MAX;
|
|
|
|
|
|
|
|
u=-1;
|
|
|
|
|
|
|
|
for(j=0;j<nm.n;j++){
|
|
|
|
|
|
|
|
if(s[j]==0&&dist[j]<min){
|
|
|
|
|
|
|
|
u=j;
|
|
|
|
|
|
|
|
min=dist[j];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(u!=-1){
|
|
|
|
|
|
|
|
s[u]=1;
|
|
|
|
|
|
|
|
for(j=0;j<nm.n;j++)
|
|
|
|
|
|
|
|
if(s[j]==0){
|
|
|
|
|
|
|
|
if(cont[u][j]<MAX&&dist[u]+cont[u][j]<dist[j]){
|
|
|
|
|
|
|
|
dist[j]=dist[u]+cont[u][j];
|
|
|
|
|
|
|
|
path[j]=u;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("智能推荐路线如下(逆序):\n");
|
|
|
|
|
|
|
|
for(i=0;i<nm.n;i++){
|
|
|
|
|
|
|
|
if(i!=v1&&i==v2){
|
|
|
|
|
|
|
|
if(s[i]==1){
|
|
|
|
|
|
|
|
num2=dist[i];
|
|
|
|
|
|
|
|
pre=i;
|
|
|
|
|
|
|
|
while(pre!=v1){
|
|
|
|
|
|
|
|
printf("%s-->",nm.adjust[pre].name);
|
|
|
|
|
|
|
|
pre=path[pre];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("%s",nm.adjust[pre].name);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else printf("路径不存在!\n");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
##概要设计
|
|
|
|
##概要设计
|
|
|
|
|
|
|
|
|
|
|
|
1. 定义了一个结构体list,包含了地铁站点信息和邻接表。
|
|
|
|
1. 定义了一个结构体list,包含了地铁站点信息和邻接表。
|
|
|
|