You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ddd/城市地铁导航系统.c

110 lines
2.0 KiB

1 year ago
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
1 year ago
#define MAX 1000
typedef struct node {
1 year ago
char a[100];
struct node* next;
}edgenode;
1 year ago
typedef struct {
1 year ago
char name[100];
1 year ago
edgenode* firstnode;
1 year ago
}vexnode;
typedef struct {
1 year ago
vexnode adjust[7];
1 year ago
int e, n;
1 year ago
}
void createjz(){//创建邻接矩阵函数
edgenode *p;
aaa();
int i;
for(i=0;i<nm.n;i++){
p=nm.adjust[i].firstnode;
while(p!=NULL){
int h;
for(h=0;h<nm.n;h++)
if(!strcmp(p->a,nm.adjust[h].name)) break;
cont[i][h]=1;
p=p->next;
}
}
}
void print() {
edgenode* p;
int i;
for(i=0;i<nm.n;i++){
printf("[%s]",nm.adjust[i].name);
p=nm.adjust[i].firstnode;
while(p!=NULL){
printf("-->[%s]",p->a);
p=p->next;
}
printf("\n");
}
1 year ago
}
1 year ago
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 year ago
int main()
{
creatnode();
createlist();
int n=10;
printf("正在初始化数据,请稍候!\n");
//proc();
printf("欢迎使用本系统!\n");
while(n){
printf("欢迎来到上海市地铁交通服务平台!\n");
printf(" 最佳出行线路推荐\n");
printf(" 退出系统!\n");
printf("请输入!\n");
scanf("%d",&n);
}
return 0;
}