中国道路交通网络信息查询系统

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

中国道路交通网络信息查询系统
【问题描述】
出于不同的目的的旅客对交通工具有不同的要求。

例如,因公出差的旅客希望在旅途中的时间尽可能短,出门旅游的游客则期望旅费尽可能省,而老年旅客则要求中转次数最少。

编制一个全国城市间的交通咨询程序,为旅客提供两种或三种最优决策的交通咨询。

【系统要求】
(1)提供对城市信息进行编辑(如:添加或删除)的功能。

(2)城市之间有两种交通工具:火车和飞机。

提供对列车时刻表和飞机航班进行编辑(增设或删除)的功能。

(3)提供两种最优决策:最快到达或最省钱到达。

全程只考虑
一种交通工具;
(4)旅途中耗费的总时间应该包括中转站的等候时间;
(5)咨询以用户和计算机的对话方式进行。

由用户输入起始站、
终点站、最优决策原则和交通工具,输出信息:最快需要
多长时间才能到达或者最少需要多少旅费才能到达,并详
细说明依次于何时乘坐哪一趟列车或哪一次班机到何地。

【程序结构图】
【算法分析】
1.新建数据
void creat_data1() //新建数据
{
int i;
printf("请输入添加火车个数: ");
scanf("%d",&t);
for(i=1;i<=t;i++)
{
printf("请输入添加火车列次: ");
scanf("%s",hc[i].hnum); printf("\n"); printf("\n请输入始站:");
scanf("%s",hc[i].kname); printf("\n"); printf("请输入终站:");
scanf("%s",hc[i].dname); printf("\n");
printf("请输入开车时间:");
scanf("%s",hc[i].ktime); printf("\n"); printf("请输入到站时间:");
scanf("%s",hc[i].dtime); printf("\n"); printf("请输入经历时间:");
scanf("%s",hc[i].ltime); printf("\n"); }
print();
}
2.添加数据
void add1() //添加数据
{
char ch;
do
{
printf("请输入添加火车列次: ");
scanf("%s",hc[t+1].hnum); printf("\n"); printf("\n请输入始站:");
scanf("%s",hc[t+1].kname); printf("\n"); printf("请输入终站:");
scanf("%s",hc[t+1].dname); printf("\n");
printf("请输入开车时间:");
scanf("%s",hc[t+1].ktime); printf("\n");
printf("请输入到站时间:");
scanf("%s",hc[t+1].dtime); printf("\n");
printf("请输入经历时间:");
scanf("%s",hc[t+1].ltime); printf("\n");
t++;
printf("是否继续添加y/n:");
getchar();
ch=getchar();
printf("\n");
}while(ch=='y');
print();
}
3.删除数据
void delet1()//删除数据
{
char num1[10];
int i,j,count=0;
printf("输入想要删除的火车列次");
scanf("%s",num1);
for (i=1;i<=t;i++)
if(strcmp(num1,hc[i].hnum)==0)
{
for(j=i;j<t+1;j++)
hc[j]=hc[j+1];
count++;
t--;
}
if(count==0) printf("没有列车信息!");
else print();
}
4.迪杰斯特拉算法
void ShortwstPath(int num) /*迪杰斯特拉算法最短路径函数*/ {
int v,w,i,t;
int final[25];
int min;
for(v=0;v<25;++v)/*初始化*/
{
final[v]=0; /*标志数组初始化*/
D[v]=G.arcs[num][v].adj;
for(w=0;w<25;++w)
P[v][w]=0;/*设空路径*/
if(D[v]<20000)/*v,v0间有边存在*/
{
P[v][num]=1;
P[v][v]=1;/*到v的最短路径上包含v0及v*/
}/*if*/
}
D[num]=0;
final[num]=1;/*初始化,v0顶点属于B集*/
/*开始主循环,每次求得v0到某个v顶点的最短路径,并加v到B集*/
for(i=0;i<25;++i)/*其余G.vexnum-1各顶点*/
{
min=20000;
for(w=0;w<25;++w)
if(!final[w])/*w顶点在V-S中*/
if(D[w]<min){v=w;min=D[w];}/*w顶点离v0更近*/
final[v]=1;/*离v0顶点最近的v加入B*/
for(w=0;w<25;++w)/*更新当前最短路径及距离*/
if(!final[w]&&((min+G.arcs[v][w].adj)<D[w]))
{
D[w]=min+G.arcs[v][w].adj;/*修改D和P数组*/
for(t=0;t<25;t++)
P[w][t]=P[v][t];
P[w][w]=1;
}/*if*/
}/*for*/
}
【程序测试】
建立如下图所示的全国交通图:
0.哈尔滨 1.长春 2.沈阳 3.大连 4.天津 5.北京 6.徐州7.呼和浩特8.兰州9.乌鲁木齐10.西宁11.西安 12.郑州13.上海14.南昌15.福州16.株洲17.武汉
18.广州19.深圳20.柳州21.贵阳22.南宁23.成都24.昆明
测试结果截图:
【源代码】
#include"string.h"
#include"stdio.h"
struct hcar
{
char hnum[10];
char kname[10];
char dname[10];
char ktime[10];
char dtime[10];
char ltime[10];
}hc[60]={{"k89", "哈尔滨", "长春", "1:00", "3:00", "2"}, {"k89", "长春", "哈尔滨", "1:00", "3:00", "2"},
{"u78", "长春", "沈阳", "3:30", "6:00", "2.5"},
{"u78", "沈阳", "长春", "3:30", "6:00", "2.5"},
{"j67", "沈阳", "大连", "6:30", "9:00", "2.5"}, {"j67", "大连", "沈阳", "6:30", "9:00", "2.5"},
{"v78", "沈阳", "天津", "9:30", "14:00", "4.5"}, {"v78", "天津", "沈阳", "9:30", "14:00", "4.5"},
{"g67", "天津", "北京", "14:30", "16:00", "1.5"},
{"g67", "北京", "天津", "14:30", "16:00", "1.5"},
{"f67", "北京", "呼和浩特", "16:30", "23:00", "6.5"},
{"f67", "呼和浩特", "北京", "16:30", "23:00", "6.5"},
{"j56", "呼和浩特", "兰州", "1:00", "3:00", "2"},
{"j56", "兰州", "呼和浩特", "1:00", "3:00", "2"},
{"v67", "兰州", "乌鲁木齐", "1:00", "3:00", "2"},
{"v67", "乌鲁木齐", "兰州", "1:00", "3:00", "2"},
{"f46", "兰州", "西宁", "1:00", "3:00", "2"},
{"f46", "西宁", "兰州", "1:00", "3:00", "2"},
{"d49", "天津", "徐州", "1:00", "3:00", "2"},
{"d49", "徐州", "天津", "1:00", "3:00", "2"},
{"c44", "徐州", "郑州", "1:00", "3:00", "2"},
{"c44", "郑州", "徐州", "1:00", "3:00", "2"},
{"h47", "郑州", "北京", "1:00", "3:00", "2"},
{"h47", "北京", "郑州", "1:00", "3:00", "2"},
{"d46", "郑州", "西安", "1:00", "3:00", "2"},
{"d46", "西安", "郑州", "1:00", "3:00", "2"},
{"v46", "西安", "兰州", "1:00", "3:00", "2"},
{"v46", "兰州", "西安", "1:00", "3:00", "2"},
{"s45", "徐州", "上海", "1:00", "3:00", "2"},
{"s45", "上海", "徐州", "1:00", "3:00", "2"},
{"t84", "上海", "南昌", "1:00", "3:00", "2"},
{"t84", "南昌", "上海", "1:00", "3:00", "2"},
{"f43", "南昌", "株洲", "1:00", "3:00", "2"},
{"f43", "株洲", "南昌", "1:00", "3:00", "2"},
{"i45", "株洲", "武汉", "1:00", "3:00", "2"},
{"i45", "武汉", "株洲", "1:00", "3:00", "2"},
{"d53", "武汉", "郑州", "1:00", "3:00", "2"},
{"d53", "郑州", "武汉", "1:00", "3:00", "2"},
{"f67", "株洲", "广州", "1:00", "3:00", "2"},
{"f67", "广州", "株洲", "1:00", "3:00", "2"},
{"h76", "广州", "深圳", "1:00", "3:00", "2"},
{"h76", "深圳", "广州", "1:00", "3:00", "2"},
{"s45", "株洲", "贵阳", "1:00", "3:00", "2"},
{"s45", "贵阳", "株洲", "1:00", "3:00", "2"},
{"o56", "株洲", "柳州", "1:00", "3:00", "2"},
{"o56", "柳州", "株洲", "1:00", "3:00", "2"},
{"d65", "贵阳", "柳州", "1:00", "3:00", "2"},
{"d65", "柳州", "贵阳", "1:00", "3:00", "2"},
{"r44", "南宁", "柳州", "1:00", "3:00", "2"},
{"r44", "柳州", "南宁", "1:00", "3:00", "2"},
{"f56", "贵阳", "成都", "1:00", "3:00", "2"},
{"f56", "成都", "贵阳", "1:00", "3:00", "2"},
{"g06", "西安", "成都", "1:00", "3:00", "2"},
{"g06", "成都", "西安", "1:00", "3:00", "2"},
{"d97", "贵阳", "昆明", "1:00", "3:00", "2"},
{"d97", "昆明", "贵阳", "1:00", "3:00", "2"},
{"d67", "成都", "昆明", "1:00", "3:00", "2"},
{"d67", "昆明", "成都", "1:00", "3:00", "2"}};
struct plane
{
char pnum[10];
char kname[10];
char dname[10];
char ktime[10];
char dtime[10];
char ltime[10];
}pl[60]={{"k89", "哈尔滨", "长春", "1:00", "3:00", "2"}, {"k89", "长春", "哈尔滨", "1:00", "3:00", "2"},
{"u78", "长春", "沈阳", "3:30", "6:00", "2.5"},
{"u78", "沈阳", "长春", "3:30", "6:00", "2.5"},
{"j67", "沈阳", "大连", "6:30", "9:00", "2.5"}, {"j67", "大连", "沈阳", "6:30", "9:00", "2.5"},
{"v78", "沈阳", "天津", "9:30", "14:00", "4.5"}, {"v78", "天津", "沈阳", "9:30", "14:00", "4.5"},
{"g67", "天津", "北京", "14:30", "16:00", "1.5"},
{"g67", "北京", "天津", "14:30", "16:00", "1.5"},
{"f67", "北京", "呼和浩特", "16:30", "23:00", "6.5"},
{"f67", "呼和浩特", "北京", "16:30", "23:00", "6.5"},
{"j56", "呼和浩特", "兰州", "1:00", "3:00", "2"},
{"j56", "兰州", "呼和浩特", "1:00", "3:00", "2"},
{"v67", "兰州", "乌鲁木齐", "1:00", "3:00", "2"},
{"v67", "乌鲁木齐", "兰州", "1:00", "3:00", "2"},
{"f46", "兰州", "西宁", "1:00", "3:00", "2"},
{"f46", "西宁", "兰州", "1:00", "3:00", "2"},
{"d49", "天津", "徐州", "1:00", "3:00", "2"},
{"d49", "徐州", "天津", "1:00", "3:00", "2"},
{"c44", "徐州", "郑州", "1:00", "3:00", "2"},
{"c44", "郑州", "徐州", "1:00", "3:00", "2"},
{"h47", "郑州", "北京", "1:00", "3:00", "2"},
{"h47", "北京", "郑州", "1:00", "3:00", "2"},
{"d46", "郑州", "西安", "1:00", "3:00", "2"},
{"d46", "西安", "郑州", "1:00", "3:00", "2"},
{"v46", "西安", "兰州", "1:00", "3:00", "2"},
{"v46", "兰州", "西安", "1:00", "3:00", "2"},
{"s45", "徐州", "上海", "1:00", "3:00", "2"},
{"s45", "上海", "徐州", "1:00", "3:00", "2"},
{"t84", "上海", "南昌", "1:00", "3:00", "2"},
{"t84", "南昌", "上海", "1:00", "3:00", "2"},
{"f43", "南昌", "株洲", "1:00", "3:00", "2"},
{"f43", "株洲", "南昌", "1:00", "3:00", "2"},
{"i45", "株洲", "武汉", "1:00", "3:00", "2"},
{"i45", "武汉", "株洲", "1:00", "3:00", "2"},
{"d53", "武汉", "郑州", "1:00", "3:00", "2"},
{"d53", "郑州", "武汉", "1:00", "3:00", "2"},
{"f67", "株洲", "广州", "1:00", "3:00", "2"},
{"f67", "广州", "株洲", "1:00", "3:00", "2"},
{"h76", "广州", "深圳", "1:00", "3:00", "2"},
{"h76", "深圳", "广州", "1:00", "3:00", "2"},
{"s45", "株洲", "贵阳", "1:00", "3:00", "2"},
{"s45", "贵阳", "株洲", "1:00", "3:00", "2"},
{"o56", "株洲", "柳州", "1:00", "3:00", "2"},
{"o56", "柳州", "株洲", "1:00", "3:00", "2"},
{"d65", "贵阳", "柳州", "1:00", "3:00", "2"},
{"d65", "柳州", "贵阳", "1:00", "3:00", "2"},
{"r44", "南宁", "柳州", "1:00", "3:00", "2"},
{"r44", "柳州", "南宁", "1:00", "3:00", "2"},
{"f56", "贵阳", "成都", "1:00", "3:00", "2"},
{"f56", "成都", "贵阳", "1:00", "3:00", "2"},
{"g06", "西安", "成都", "1:00", "3:00", "2"},
{"g06", "成都", "西安", "1:00", "3:00", "2"},
{"d97", "贵阳", "昆明", "1:00", "3:00", "2"},
{"d97", "昆明", "贵阳", "1:00", "3:00", "2"},
{"d67", "成都", "昆明", "1:00", "3:00", "2"},
{"d67", "昆明", "成都", "1:00", "3:00", "2"}};; int t;//全局变量
typedef struct ArcCell{
int adj;
char *info;
}ArcCell; /*定义边的类型*/
typedef struct VertexType{
int number;
char *place;
}VertexType; /*定义顶点的类型*/
typedef struct{
VertexType vex[25];
ArcCell arcs[25][25];
int vexnum,arcnum;
}MGraph; /*定义图的类型*/
MGraph G; /*把图定义为全局变量*/
char
*sa[30]={"a","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a"," a","a","a","a",
"a","a","a","a","a","a","a","a","a","a"};
int P[25][25];
long int D[25];
void print()
{
int n;
void printh();
void printp();
void print1();
void print2();
do{
printf("\t\t\t时刻表\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("\t\t\t1.火车时刻表\n") ;
printf("\t\t\t2.飞机时刻表\n");
printf("\t\t\t3.退出\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("请输入序号选择相应操作:");
scanf("%d",&n);
switch(n)
{
case 1:print1();printh();break;
case 2:print2();printp();break;
case 3:printf("欢迎使用\n");break;
default: printf("输入错误");
}
}while(n!=3);
}
void printh()
{
int n;
void creat_data1();
void add1();
void delet1();
do{
printf("\t\t\t火车时刻表\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("\t\t\t1.新建数据\n") ;
printf("\t\t\t2.添加\n");
printf("\t\t\t3.删除\n");
printf("\t\t\t4.退出\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"); printf("请输入序号选择相应操作:");
scanf("%d",&n);
switch(n)
{
case 1:creat_data1();break;
case 2:add1();break;
case 3:delet1();break;
case 4:printf("欢迎使用\n");break;
default: printf("输入错误");
}
}while(n!=4);
}
void printp()
{
int n;
void creat_data2();
void add2();
void delet2();
do{
printf("\t\t\t飞机时刻表\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("\t\t\t1.新建数据\n") ;
printf("\t\t\t2.添加\n");
printf("\t\t\t3.删除\n");
printf("\t\t\t4.退出\n");
printf("\t~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
printf("请输入序号选择相应操作:");
scanf("%d",&n);
switch(n)
{
case 1:creat_data2();break;
case 2:add2();break;
case 3:delet2();break;
case 4:printf("欢迎使用\n");break;
default: printf("输入错误");
}
}while(n!=4);
}
void print1()
{
int i;
printf("\t\t列次始站终站开车到站历时\n");
printf("\t\t---------------------------------------------------\n");
for(i=0;i<58;i++)
printf("\t\t %s %s %s %s %s %s
\n",hc[i].hnum,hc[i].kname,hc[i].dname,hc[i].ktime,hc[i].dtime,hc[i].l time);
for(i=58;i<=(58+t);i++)
printf("\t\t %s %s %s %s %s %s
\n",hc[i].hnum,hc[i].kname,hc[i].dname,hc[i].ktime,hc[i].dtime,hc[i].l time);
printf("\t\t---------------------------------------------------\n\n");
}
void creat_data1() //新建数据
{
int i;
printf("请输入添加火车个数: ");
scanf("%d",&t);
for(i=1;i<=t;i++)
{
printf("请输入添加火车列次: ");
scanf("%s",hc[i].hnum); printf("\n"); printf("\n请输入始站:");
scanf("%s",hc[i].kname); printf("\n"); printf("请输入终站:");
scanf("%s",hc[i].dname); printf("\n");
printf("请输入开车时间:");
scanf("%s",hc[i].ktime); printf("\n"); printf("请输入到站时间:");
scanf("%s",hc[i].dtime); printf("\n"); printf("请输入经历时间:");
scanf("%s",hc[i].ltime); printf("\n"); }
//sum_stu();
print();
}
void add1() //添加数据
{
char ch;
do
{
printf("请输入添加火车列次: ");
scanf("%s",hc[t+1].hnum); printf("\n"); printf("\n请输入始站:");
scanf("%s",hc[t+1].kname); printf("\n"); printf("请输入终站:");
scanf("%s",hc[t+1].dname); printf("\n");
printf("请输入开车时间:");
scanf("%s",hc[t+1].ktime); printf("\n");
printf("请输入到站时间:");
scanf("%s",hc[t+1].dtime); printf("\n");
printf("请输入经历时间:");
scanf("%s",hc[t+1].ltime); printf("\n");
t++;
printf("是否继续添加y/n:");
getchar();
ch=getchar();
printf("\n");
}while(ch=='y');
//sum_stu();
print();
}
void delet1()//删除数据
{
char num1[10];
int i,j,count=0;
printf("输入想要删除的火车列次");
scanf("%s",num1);
for (i=1;i<=t;i++)
if(strcmp(num1,hc[i].hnum)==0)
{
for(j=i;j<t+1;j++)
hc[j]=hc[j+1];
count++;
t--;
}
if(count==0) printf("没有列车信息!");
else print();
}
void print2()
{
int i;
printf("\t\t航次始站终站开机到场历时\n");
printf("\t\t---------------------------------------------------\n");
for(i=0;i<58;i++)
printf("\t\t %s %s %s %s %s %s
\n",pl[i].pnum,pl[i].kname,pl[i].dname,pl[i].ktime,pl[i].dtime,pl[i].l time);
for(i=58;i<=(58+t);i++)
printf("\t\t %s %s %s %s %s %s
\n",pl[i].pnum,pl[i].kname,pl[i].dname,pl[i].ktime,pl[i].dtime,pl[i].l time);
printf("\t\t---------------------------------------------------\n\n"); }
void creat_data2() //新建数据
{
int i;
printf("请输入添加飞机个数: ");
scanf("%d",&t);
for(i=1;i<=t;i++)
{
printf("请输入添加飞机列次: ");
scanf("%s",pl[i].pnum); printf("\n");
printf("\n请输入始站:");
scanf("%s",pl[i].kname); printf("\n");
printf("请输入终站:");
scanf("%s",pl[i].dname); printf("\n");
printf("请输入开车时间:");
scanf("%s",pl[i].ktime); printf("\n");
printf("请输入到站时间:");
scanf("%s",pl[i].dtime); printf("\n");
printf("请输入经历时间:");
scanf("%s",pl[i].ltime); printf("\n");
}
//sum_stu();
print();
}
void add2() //添加数据
{
char ch;
do
{
printf("请输入添加飞机列次: ");
scanf("%s",pl[t+1].pnum); printf("\n"); printf("\n请输入始站:");
scanf("%s",pl[t+1].kname); printf("\n"); printf("请输入终站:");
scanf("%s",pl[t+1].dname); printf("\n");
printf("请输入开车时间:");
scanf("%s",pl[t+1].ktime); printf("\n"); printf("请输入到站时间:");
scanf("%s",pl[t+1].dtime); printf("\n"); printf("请输入经历时间:");
scanf("%s",pl[t+1].ltime); printf("\n"); t++;
printf("是否继续添加y/n:");
getchar();
ch=getchar();
printf("\n");
}while(ch=='y');
//sum_stu();
print();
}
void delet2()//删除数据
{
char num2[10];
int i,j,count=0;
printf("输入想要删除的飞机列次");
scanf("%s",num2);
for (i=1;i<=t;i++)
if(strcmp(num2,pl[i].pnum)==0)
{
for(j=i;j<t+1;j++)
pl[j]=pl[j+1];
count++;
t--;
}
if(count==0) printf("没有飞机信息!");
else print();
}
void CreateUDN(int v,int a) /*造图函数*/ { int i,j; G.vexnum=v;
G.arcnum=a;
for(i=0;i<G.vexnum;++i)
G.vex[i].number=i;
G.vex[0].place="哈尔滨";
G.vex[1].place="长春";
G.vex[2].place="沈阳";
G.vex[3].place="大连";
G.vex[4].place="天津";
G.vex[5].place="北京";
G.vex[6].place="徐州";
G.vex[7].place="呼和浩特";
G.vex[8].place="兰州";
G.vex[9].place="乌鲁木齐";
G.vex[10].place="西宁";
G.vex[11].place="西安";
G.vex[12].place="郑州";
G.vex[13].place="上海";
G.vex[14].place="南昌";
G.vex[15].place="福州";
G.vex[16].place="株洲";
G.vex[17].place="武汉";
G.vex[18].place="广州";
G.vex[19].place="深圳";
G.vex[20].place="柳州";
G.vex[21].place="贵阳";
G.vex[22].place="南宁";
G.vex[23].place="成都";
G.vex[24].place="昆明";
for(i=0;i<G.vexnum;++i)
for(j=0;j<G.vexnum;++j)
G.arcs[i][j].adj=20000;
G.arcs[0][1].adj=G.arcs[1][0].adj=242;
G.arcs[1][2].adj=G.arcs[2][1].adj=305;
G.arcs[2][3].adj=G.arcs[3][2].adj=397;
G.arcs[2][4].adj=G.arcs[4][2].adj=704;
G.arcs[4][5].adj=G.arcs[5][4].adj=137;
G.arcs[4][6].adj=G.arcs[6][4].adj=674;
G.arcs[5][7].adj=G.arcs[7][5].adj=668;
G.arcs[7][8].adj=G.arcs[8][7].adj=1145; G.arcs[8][9].adj=G.arcs[9][8].adj=1892;
G.arcs[8][10].adj=G.arcs[10][8].adj=216; G.arcs[6][12].adj=G.arcs[12][6].adj=319; G.arcs[5][12].adj=G.arcs[12][5].adj=695; G.arcs[11][12].adj=G.arcs[12][11].adj=511;
G.arcs[8][11].adj=G.arcs[11][8].adj=676;
G.arcs[6][13].adj=G.arcs[13][6].adj=651; G.arcs[13][14].adj=G.arcs[14][13].adj=325;
G.arcs[14][15].adj=G.arcs[15][14].adj=622;
G.arcs[14][16].adj=G.arcs[16][14].adj=367;
G.arcs[16][17].adj=G.arcs[17][16].adj=409;
G.arcs[17][12].adj=G.arcs[12][17].adj=534;
G.arcs[16][21].adj=G.arcs[21][16].adj=902;
G.arcs[21][23].adj=G.arcs[23][21].adj=967;
G.arcs[23][11].adj=G.arcs[11][23].adj=842;
G.arcs[21][24].adj=G.arcs[24][21].adj=639;
G.arcs[23][24].adj=G.arcs[24][23].adj=1100;
G.arcs[18][16].adj=G.arcs[16][18].adj=675;
G.arcs[18][19].adj=G.arcs[19][18].adj=140;
G.arcs[16][20].adj=G.arcs[20][16].adj=672;
G.arcs[20][21].adj=G.arcs[21][20].adj=607;
G.arcs[20][22].adj=G.arcs[22][20].adj=255; }
void narrate() /*说明函数*/
{
int i,k=0;
printf("\n以下是选项:\n\n");
for(i=0;i<25;i++)
{
printf("(%d) %-10s",i,G.vex[i].place);
k=k+1;
if(k%4==0)
printf("\n\n");
}
}
void ShortwstPath(int num) /*弗洛伊德算法最短路径函数*/
{
int v,w,i,t;
int final[25];
int min;
for(v=0;v<25;++v)/*初始化*/
{
final[v]=0; /*标志数组初始化*/
D[v]=G.arcs[num][v].adj;
for(w=0;w<25;++w)
P[v][w]=0;/*设空路径*/
if(D[v]<20000)/*v,v0间有边存在*/
{
P[v][num]=1;
P[v][v]=1;/*到v的最短路径上包含v0及v*/
}/*if*/
}
D[num]=0;
final[num]=1;/*初始化,v0顶点属于B集*/
/*开始主循环,每次求得v0到某个v顶点的最短路径,并加v到B集*/ for(i=0;i<25;++i)/*其余G.vexnum-1各顶点*/
{
min=20000;
for(w=0;w<25;++w)
if(!final[w])/*w顶点在V-S中*/
if(D[w]<min){v=w;min=D[w];}/*w顶点离v0更近*/
final[v]=1;/*离v0顶点最近的v加入B*/
for(w=0;w<25;++w)/*更新当前最短路径及距离*/
if(!final[w]&&((min+G.arcs[v][w].adj)<D[w])) {
D[w]=min+G.arcs[v][w].adj;/*修改D和P数组*/
for(t=0;t<25;t++)
P[w][t]=P[v][t];
P[w][w]=1;
}/*if*/
}/*for*/
}
void output(int place1,int place2) /*输出函数*/
{
int i=1, a,b,c,d,q=0;
a=place2;
if(a!=place1)
{
printf("\n最短路径从%s
到%s\n",G.vex[place1].place,G.vex[place2].place);
printf("\n最短距离%dm.\n",D[a]);
printf("%s",G.vex[place1].place);
sa[0]=G.vex[place1].place;
d=place1;
for(c=0;c<30;++c)
{
gate:;
P[a][place1]=0;
for(b=0;b<25;b++)
{
if(G.arcs[d][b].adj<20000&&P[a][b]) {
printf("----->%s",G.vex[b].place);
sa[i]=G.vex[b].place;
i++;
q=q+1;
P[a][b]=0;
d=b;
if(q%4==0) printf("\n"); goto gate;
}
}
}
}
}
void hcaroutput() /*输出函数*/
{
printf("\n火车时刻表:\n");
printf("\t\t列次始站终站开车到站历时\n");
printf("\n\t\t---------------------------------------------------\n"); for(int k=0;k<30;k++)
{
for(int i=0;i<58;i++)
if(strcmp(sa[k],hc[i].kname)==0 && strcmp(sa[k+1],hc[i].dname)==0) {
printf("\t\t %s %s %s %s %s %s
\n",hc[i].hnum,hc[i].kname,hc[i].dname,hc[i].ktime,hc[i].dtime,hc[i].l time);
}
}
printf("\n\t\t---------------------------------------------------\n");
}
void planeoutput() /*输出函数*/
{
printf("\n飞机时刻表:\n");
printf("\t\t航次始站终站开机到场历时\n");
printf("\n\t\t---------------------------------------------------\n"); for(int k=0;k<30;k++)
{
for(int i=0;i<58;i++)
if(strcmp(sa[k],pl[i].kname)==0 && strcmp(sa[k+1],pl[i].dname)==0) {
printf("\t\t %s %s %s %s %s %s
\n",pl[i].pnum,pl[i].kname,pl[i].dname,pl[i].ktime,pl[i].dtime,pl[i].l。

相关文档
最新文档