Compare commits

...

2 Commits
master ... void

Author SHA1 Message Date
孙艺哲 d7366c8c3a fdg
1 year ago
孙艺哲 3fe6a269c2 void
1 year ago

@ -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包含了地铁站点信息和邻接表。

@ -32,10 +32,76 @@
}
void createlist() {
edgenode *p;
//下面是肇嘉浜路的邻接表
//...
//下面是上海体育馆的邻接表
//...
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "东安路");
p->next = nm.adjust[0].firstnode;
nm.adjust[0].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "嘉善路");
p->next = nm.adjust[0].firstnode;
nm.adjust[0].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "徐家汇");
p->next = nm.adjust[0].firstnode;
nm.adjust[0].firstnode = p;
//下面是东安路的邻接表
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "肇嘉浜路");
p->next = nm.adjust[1].firstnode;
nm.adjust[1].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "上海体育场");
p->next = nm.adjust[1].firstnode;
nm.adjust[1].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "大木桥路");
p->next = nm.adjust[1].firstnode;
nm.adjust[1].firstnode = p;
//下面是上海体育场的邻接表
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "东安路");
p->next = nm.adjust[2].firstnode;
nm.adjust[2].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "上海体育馆");
p->next = nm.adjust[2].firstnode;
nm.adjust[2].firstnode = p;
//下面是嘉善路的邻接表
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "大木桥路");
p->next = nm.adjust[3].firstnode;
nm.adjust[3].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "肇嘉浜路");
p->next = nm.adjust[3].firstnode;
nm.adjust[3].firstnode = p;
//下面是大木桥路
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "东安路");
p->next = nm.adjust[4].firstnode;
nm.adjust[4].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "嘉善路");
p->next = nm.adjust[4].firstnode;
nm.adjust[4].firstnode = p;
//下面是徐家汇
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "肇嘉浜路");
p->next = nm.adjust[5].firstnode;
nm.adjust[5].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "上海体育馆");
p->next = nm.adjust[5].firstnode;
nm.adjust[5].firstnode = p;
//下面是上海体育馆
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "徐家汇");
p->next = nm.adjust[6].firstnode;
nm.adjust[6].firstnode = p;
p = (edgenode*)malloc(sizeof(edgenode));
strcpy(p->a, "上海体育场");
p->next = nm.adjust[5].firstnode;
nm.adjust[6].firstnode = p;
}
int cont[100][100];//邻接矩阵
void aaa(){

Loading…
Cancel
Save