|
|
|
#include <iostream>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <malloc.h>
|
|
|
|
#include "type.h"
|
|
|
|
#include "menu.h"
|
|
|
|
#include "function.h"
|
|
|
|
#include "creat.h"
|
|
|
|
#include "short.h"
|
|
|
|
|
|
|
|
int CreatGrath(MatGrath &G); //创造图
|
|
|
|
int DFS(MatGrath &G,int m);
|
|
|
|
|
|
|
|
void ShortestPath(MatGrath &G,int v,int w); //Dijkstra算法求最短路径
|
|
|
|
void Ppath(MatGrath &G,int path[],int w,int v); //前向递归查找路径上的顶点
|
|
|
|
|
|
|
|
int Ppath1(MatGrath &G,int path[][MAXV],int v,int w);//前向递归查找路径上的顶点
|
|
|
|
void ShortestMoney(MatGrath &G,int v,int w); //用floyd算法求最少费用
|
|
|
|
|
|
|
|
int menu(void);
|
|
|
|
|
|
|
|
int delet(MatGrath &G,int y,int x);
|
|
|
|
|
|
|
|
int search(MatGrath &G); //查找某一个城市的信息
|
|
|
|
void addbian(MatGrath &G); //增加城市的边信息
|
|
|
|
void adddian(MatGrath &G); //增加城市的信息
|
|
|
|
void modify(MatGrath &G); //修改城市信息
|
|
|
|
int display(MatGrath &G);//输出所有城市信息
|
|
|
|
|
|
|
|
void danyuan(MatGrath &G,int d); //求两点之间的最短路径
|
|
|
|
int Ppath2(MatGrath &G,int path[],int i,int v);
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
int a; //case语句的选择
|
|
|
|
int v,w; //用于求最好费用以及最短路程
|
|
|
|
int b; //选择两种最短
|
|
|
|
int c; //选择增加点还是增加边
|
|
|
|
int d; //定义单源的源点
|
|
|
|
int m; //用于DFS算法
|
|
|
|
int x,y; //代表删除点的两边城市的编号
|
|
|
|
|
|
|
|
MatGrath G;
|
|
|
|
system("color 1A"); /*修改控制台的颜色信息,改为绿字红底的模式*/
|
|
|
|
CreatGrath(G);
|
|
|
|
printf(" ■ ■■■■■■■■■■■■■■■■ ■ \n");
|
|
|
|
printf(" ■ ■欢迎使用城市公路导航系统■ ■ \n");
|
|
|
|
printf(" ■ ■■■■■■■■■■■■■■■■ ■ \n");
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
printf(" 编号 城市名称\n");
|
|
|
|
printf(" 1 济南市\n");
|
|
|
|
printf(" 2 德州市\n");
|
|
|
|
printf(" 3 淄博市\n");
|
|
|
|
printf(" 4 潍坊市\n");
|
|
|
|
printf(" 5 烟台市\n");
|
|
|
|
printf(" 6 威海市\n");
|
|
|
|
printf(" 7 青岛市\n");
|
|
|
|
printf(" 8 日照市\n");
|
|
|
|
printf(" 9 临沂市\n");
|
|
|
|
printf(" 10 济宁市\n");
|
|
|
|
printf(" 11 泰安市\n");
|
|
|
|
printf(" 12 滨州市\n");
|
|
|
|
printf(" 13 菏泽市\n");
|
|
|
|
printf(" 14 即墨市\n");
|
|
|
|
printf(" 15 胶州市\n");
|
|
|
|
printf(" 16 胶南市\n");
|
|
|
|
printf(" 17 诸城市\n");
|
|
|
|
printf(" 18 高密市\n");
|
|
|
|
printf(" 19 安丘市\n");
|
|
|
|
printf(" 20 莒县\n");
|
|
|
|
printf(" 21 平度市\n");
|
|
|
|
printf(" 22 莱西市\n");
|
|
|
|
printf(" 23 莱阳市\n");
|
|
|
|
printf(" 24 海阳市\n");
|
|
|
|
printf(" 25 乳山市\n");
|
|
|
|
printf(" 26 文登市\n");
|
|
|
|
printf(" 27 荣成市\n");
|
|
|
|
printf(" 28 牟平市\n");
|
|
|
|
printf(" 29 蓬莱市\n");
|
|
|
|
printf(" 30 栖霞市\n");
|
|
|
|
printf(" 31 莱州市\n");
|
|
|
|
printf(" 32 招远市\n");
|
|
|
|
printf(" 33 龙口市\n");
|
|
|
|
printf(" 34 昌邑市\n");
|
|
|
|
printf(" 35 昌乐\n");
|
|
|
|
printf(" 36 孝光市\n");
|
|
|
|
printf(" 37 青州市\n");
|
|
|
|
printf(" 38 临朐\n");
|
|
|
|
printf(" 39 沂水\n");
|
|
|
|
printf(" 40 广饶\n");
|
|
|
|
printf(" 41 东营市\n");
|
|
|
|
printf(" 42 沂源\n");
|
|
|
|
printf(" 43 恒台\n");
|
|
|
|
printf(" 44 博兴\n");
|
|
|
|
printf(" 45 博山\n");
|
|
|
|
printf(" 46 沂南\n");
|
|
|
|
printf(" 47 蒙阴\n");
|
|
|
|
printf(" 48 莱芜市\n");
|
|
|
|
while(a!=9)
|
|
|
|
{
|
|
|
|
a=menu();
|
|
|
|
switch(a)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
printf("1-路径最短,2-费用最少,请选择");
|
|
|
|
scanf("%d",&b);
|
|
|
|
scanf("%d",&v);
|
|
|
|
scanf("%d",&w);
|
|
|
|
if(b==1)
|
|
|
|
{
|
|
|
|
|
|
|
|
ShortestPath(G,v,w);
|
|
|
|
}
|
|
|
|
if(b==2)
|
|
|
|
{
|
|
|
|
ShortestMoney(G,v,w);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
search(G);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
modify(G);
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
printf("1-增加边,2-增加点");
|
|
|
|
scanf("%d",&c);
|
|
|
|
|
|
|
|
if(c==1)
|
|
|
|
addbian(G);
|
|
|
|
else
|
|
|
|
adddian(G);
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
display(G);
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
scanf("%d",&d);
|
|
|
|
danyuan(G,d);
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
scanf("%d",&m);
|
|
|
|
DFS(G,m);
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
scanf("%d",&y);
|
|
|
|
scanf("%d",&x);
|
|
|
|
delet(G,y,x);
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
printf("欢迎使用,再见!\n");
|
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|