资源简介
设计一个交通咨询系统,能让旅客咨询从任一城市顶点到另一城市顶点之间的最短路径(里程)或最低花费或最少时间等问题。对于不同咨询要求,可输入城市间的路程或所需时间或所需费用。
完成功能的详细说明:
1.创建图的存储结构使用邻接矩阵。
2.查询分为两类。一类是能让旅客咨询从一个城市到另外所有城市的最短路径(要求使用迪杰斯特拉算法),显示出所有路径,按升序排列。第二类是任意两个城市间的最短路径(要求使用弗洛伊德算法),显示最短路径。
代码片段和文件信息
#include
#include
#include
#define VertexType int
#define MAXSIZE 26
#define MAXCOST 10000
#define INFINITY 999999
using namespace std;
typedef struct{
int length;
int time;
int fee;
}edge_info;
typedef struct{
VertexType vex[MAXSIZE];
edge_info edges[MAXSIZE][MAXSIZE];
int vexnumedgenum;
}MGraph;
void cities(int m){
switch(m){
case 1:cout<<“北京“;break;
case 2:cout<<“长春“;break;
case 3:cout<<“成都“;break;
case 4:cout<<“大连“;break;
case 5:cout<<“福州“;break;
case 6:cout<<“广州“;break;
case 7:cout<<“贵阳“;break;
case 8:cout<<“哈尔滨“;break;
case 9:cout<<“呼和浩特“;break;
case 10:cout<<“昆明“;break;
case 11:cout<<“兰州“;break;
case 12:cout<<“柳州“;break;
case 13:cout<<“南昌“;break;
case 14:cout<<“南宁“;break;
case 15:cout<<“上海“;break;
case 16:cout<<“沈阳“;break;
case 17:cout<<“深圳“;break;
case 18:cout<<“天津“;break;
case 19:cout<<“武汉“;break;
case 20:cout<<“乌鲁木齐“;break;
case 21:cout<<“西安“;break;
case 22:cout<<“西宁“;break;
case 23:cout<<“徐州“;break;
case 24:cout<<“郑州“;break;
case 25:cout<<“株洲“;break;
default:cout<<“错误,系统无此城市!“;break;
}
}
void CreatMGraph(MGraph *G){
int ijktfs;
ifstream infile;
infile.open(“C:\\交通系统数据.txt“ios::in|ios::out);
if(!infile){
cerr<<“打开‘交通系统数据.txt’文件失败!“< infile.close();
return;
}
infile>>G->edgenum>>G->vexnum;
for(i=1;i<=G->vexnum;i++)
G->vex[i]=i;
for(i=0;i<=G->vexnum;i++){
for(j=0;j<=G->vexnum;j++){
G->edges[i][j].length=INFINITY;
G->edges[i][j].time=INFINITY;
G->edges[i][j].fee=INFINITY;
}
}
for(s=0;sedgenum;s++){
infile>>i>>j>>f>>t>>k;
G->edges[i][j].fee=f;
G->edges[j][i].fee=f;
G->edges[i][j].time=t;
G->edges[j][i].time=t;
G->edges[i][j].length=k;
G->edges[j][i].length=k;
}
infile.close();
}
void window()
{
cout<<“\n\n\t\t*****************交通查询系统*******************\n\n“;
cout<<“1:北京 2:长春 3:成都 4:大连 5:福州 6:广州 7:贵阳 8:哈尔滨 9:呼和浩特\n“;
cout<<“10:昆明 11:兰州 12:柳州 13:南昌 14:南宁 15:上海 16:沈阳 17:深圳 \n“;
cout<<“18:天津 19:武汉 20:乌鲁木齐 21:西安 22:西宁 23:徐州 24:郑州 25:株州\n“;
}
void shortestpath1(MGraph *Gint v0int n){
int kl;
int min;
int e[MAXSIZE][MAXSIZE];
int ijvpre;
int p[30]d[30];
int final[30]shuchu[30];
switch(n){
case 1:for(k=0;k for(l=0;l if(G->edges[k][l].length e[k][l]=G->edges[k][l].length;
else e[k][l]=INFINITY;
}
break;
case 2:for(k=0;k for(l=0;l if(G->edges[k][l].length e[k][l]=G->edges[k][l].time;
else e[k][l]=INFINITY;
}
break;
case 3:for(k=0;k for(l=0;l if(G->edges[k][l].length e[k][l]=G->edges[k][l].fee;
else e[k][l]=INFINITY;
}
break;
default:cou
相关资源
- 利用C++哈希表的方法实现电话号码查
- 学校超市选址问题(数据结构C语言版
- 数据结构,迷宫问题C语言版源代码
- DSDEMO-C演示(数据结构C语言版 严蔚敏
- 数据结构 图的遍历源代码
- 数据结构实验源代码集
- 实验报告:数据结构长整数四则运算
- 数据结构教程李春葆第五版书中例题
- 吕鑫vc6c++数据结构视频源码
- 数据结构教程李春葆第五版课后答案
- 李春葆课后习题答案(数据结构教材
- 数据结构1800题 题+答案(全)
- 数据结构(C语言版)ppt课件,清华,
- c++常用游戏算法及数据结构设计
- 数据结构超全面复习导图
- 《Data Structures and Algorithm Analysis in C
- 数据结构C语言版教学笔记严蔚敏
- 数据结构C语言版期末考试试题(有答
- 多功能计算器实现C++代码以及代码详
- C语言数据结构银行客户排队
- C语言实现栈操作
- 简易学生管理系统源码 数据结构 大作
- 数据结构与C语言综合习题集
- 数据结构实验——赫夫曼树相关
- C语言进阶源码---基于graphics实现图书
- 数据结构——C++语言描述 陈慧南
- 广东工业大学数据结构课程设计航空
- 数据结构课程设计扑克牌排序
- 数据结构各种算法实现(C++模板),
- (严版C语言版数据结构源码.rar
评论
共有 条评论