Main.cpp
上传用户:yingjiejs
上传日期:2022-06-05
资源大小:841k
文件大小:4k
- /*
- *导游系统的实验代码
- *这里采用是迪杰斯特的算法进行最短路径的寻找
- */
- #include "Head.h"
- //主函数
- void main()
- {
- const int numv = 8; //节点的个数
- int choose=1,i,j, vv=0,vvt=0;
- int which;//功能选择变量
- string name; //插入顶点的值
-
- //这里采用图的邻接矩阵进行存储,其中MAX表示无穷大
- //路径长度的矩阵
- int cost[numv][numv]={
- {MAX,130,80,260,MAX,MAX,MAX,MAX},
- {130,MAX,MAX,75,MAX,265,MAX,MAX},
- {80,MAX,MAX,MAX,50,MAX,MAX,MAX},
- {260,75,MAX,MAX,120,85,400,MAX},
- {MAX,MAX,50,120,MAX,MAX,350,200},
- {MAX,265,MAX,85,MAX,MAX,120,MAX},
- {MAX,MAX,MAX,400,350,120,MAX,150},
- {MAX,MAX,MAX,MAX,200,MAX,150,MAX}};
- //每一条边的信息
- string arcifoss[numv][numv]={
- {"11","12","13","14","15","16","17","18"},
- {"21","22","23","24","25","26","27","28"},
- {"31","32","33","34","35","36","37","38"},
- {"41","42","43","44","45","46","47","48"},
- {"51","52","53","54","55","56","57","58"},
- {"61","62","63","64","65","66","67","68"},
- {"71","72","73","74","75","76","77","78"},
- {"81","82","83","84","85","86","87","88"}};
- //每个节点的名字
- string vname[numv]={"综A学楼","综B教学楼","嘉庚图书馆 ","西苑餐厅 ","计算机学院","尚大楼 ","综合实验楼","校医院 "};
-
- //代号
- string vnos[numv]={"J4","J3","J2","J1","Q4","Q3","Q2","Q1"};
- //简介
- string vifo[numv]={"教学专用","教学专用","用于学生的读书自习","在第五社区的食堂","培养计算机专业学生","行政办公楼","用于做物理实验","学生的日常保健和医疗中心"};
-
-
- //初始化图
- MGraph G;
- InitGraph(G,cost[0], vname,vnos,vifo,arcifoss, numv);
- while ( choose==1 )
- {
- nemu();
- scanf("%d",&which);
- switch( which )
- {
-
- case 1: //1.输出顶点信息
- PutOutVexInfo(G);
- getchar();getchar(); break;
- case 2: //2.输出边的信息
- PutOutArcInfo(G);
- getchar();getchar(); break;
- case 3: // 3.修改某条路径
- printf("改变两个节点间的权重(长度):");
- printf("请输入第一节点:");
- scanf("%d",&i);
- printf("第二个节点值:");
- scanf("%d",&j);
- printf("你要改变的节点是: 从%s 到 %s的权重n",G.vertex[i].c_str(),G.vertex[j].c_str());
- int length;
- printf("请输入从%s 到 %s的权重n",G.vertex[i].c_str(),G.vertex[j].c_str());
- scanf("%d",&length);
- SetArc(G,i,j,length);
- getchar();getchar();break;
- case 4: // 删除某一条边
- int pos1;
- int pos2;
- printf("请输入两顶点:n");
- scanf("%d %d",&pos1,&pos2);
- DeleteArc(G,pos1,pos2);
- getchar();getchar();break;
- case 5: //两地最短的路径
- printf("请输入源顶点:n");
- scanf("%d",&vv);
- printf("请输入结束顶点:n");
- scanf("%d",&vvt);
- Dijkstra(G,vv,vvt,MUL);
- getchar();getchar();break;
- case 6: //到某地最短路径
- printf("请输入顶点:n");
- scanf("%d",&vv);
- Dijkstra(G,vv,vvt,EVERYONE);
- getchar();getchar();break;
- case 7: //退出
- choose=0;
- getchar();getchar();break;
- }
- }
- }
-