当前位置:   article > 正文

数据结构 -- 景区旅游信息管理系统_景区旅游信息管理系统数据结构

景区旅游信息管理系统数据结构

景区旅游信息管理系统

【问题描述】

在旅游景区,经常会遇到游客打听从一个景点到另一个景点的最短路径和最短距离,这类游客不喜欢按照导游图的线路来游览,而是挑选自己感兴趣的景点游览。为于帮助这类游客信息查询,就需要计算出所有景点之间最短路径和最短距离。算法采用迪杰斯特拉算法或弗洛伊德算法均可。建立一个景区旅游信息管理系统,实现的主要功能包括制订旅游景点导游线路策略和制订景区道路铺设策略。

课程

任务中景点分布是一个无向带权连通图,图中边的权值是景点之间的距离。

    (1)景区旅游信息管理系统中制订旅游景点导游线路策略,首先通过遍历景点,给出一个入口景点,建立一个导游线路图,导游线路图用有向图表示。遍历采用深度优先策略,这也比较符合游客心理。

   (2)为了使导游线路图能够优化,可通过拓朴排序判断图中有无回路,若有回路,则打印输出回路中的景点,供人工优化。

   (3)在导游线路图中,还为一些不愿按线路走的游客提供信息服务,比如从一个景点到另一个景点的最短路径和最短距离。在本线路图中将输出任意景点间的最短路径和最短距离。

   (4)在景区建设中,道路建设是其中一个重要内容。道路建设首先要保证能连通所有景点,但又要花最小的代价,可以通过求最小生成树来解决这个问题。本任务中假设修建道路的代价只与它的里程相关。

【基本要求】

本任务应有如下功能模块:

  创建景区景点分布图;

  输出景区景点分布图(邻接矩阵)

  输出导游线路图;

  判断导游线路图有无回路;

  求两个景点间的最短路径和最短距离;

  输出道路修建规划图。

  主程序用菜单选项供用户选择功能模块。

因为时间很仓促,做的不是很好,判断导游线路图我没用拓扑排序(写了没用) .

然后我的边和景点信息存在工程下目录edge 和 map 两个文件中.

链接:https://pan.baidu.com/s/1fkD5C8Hfp1KsNGDb91pSgw 
提取码:9oox 
*** 2021/1/2 更新

链接:https://pan.baidu.com/s/1j7SKDg2aVfd56lohMpf_XA 
提取码:1234 
--来自百度网盘超级会员V4的分享

*** 2023/12/13 更新

代码 :  

  1. #include <cstdio>
  2. #include <cstdlib>
  3. #include <string>
  4. #include <cstring>
  5. #include <algorithm>
  6. #define path "map.txt"
  7. #include <windows.h>
  8. #include <vector>
  9. #include <iostream>
  10. using namespace std ;
  11. const int MAX = 105 ;
  12. const int inf = 0x3f3f3f;
  13. // 景区旅游信息管理系统
  14. typedef struct node{
  15. char PlaceName[MAX] ; // 景点的名字 
  16. int number ; // 景点编号 
  17. char PlaceNum[MAX] ; // 编号 ;
  18. }Node;
  19. typedef struct Tornode{
  20. int u ;
  21. int v ;
  22. int weight ;
  23. }TorNode; // 起点终点和距离 ;
  24. typedef struct matGraph{
  25. int map[MAX][MAX] ;
  26. int n , e ;
  27. }MatGraph;// 完整的图邻接矩阵类型
  28. typedef struct NODE{
  29. int key ;// 关键字项
  30. Node infor ; // 信息
  31. struct NODE *lchild ;
  32. struct NODE *rchild ;
  33. }BSTNode;
  34. typedef struct ANode{
  35. int adjvex ; // 编号
  36. struct ANode *nextarc ;
  37. int weight ;
  38. }ArcNode ; // 边节点的类型
  39. typedef struct Vnode{
  40. ArcNode *fitstarc ;
  41. int count ;
  42. }VNode; // 邻接表的头结点类型
  43. typedef struct {
  44. VNode adjlist[MAX] ;
  45. int n , e ; // 边数和顶点数
  46. }AdjGraph;
  47. int vis[MAX] ;
  48. int dis[MAX] ;
  49. int count1 ;
  50. BSTNode *MapVex[MAX] ; // 顶点
  51. void CreatMatGragh(MatGraph &GT ,int n ,int e , int pot, TorNode Gr[MAX][MAX])
  52. {
  53. // 创建导游有向图 ;
  54. for(int i = 1 ; i<=n ; i++)
  55. {
  56. for(int j = 1 ; j <=n ;j++)
  57. {
  58. if(i == j )
  59. {
  60. GT.map[i][j] = 0 ;
  61. }
  62. GT.map[i][j] = inf ;
  63. }
  64. }
  65. for(int i = 1 ; i<=e ; i++)
  66. {
  67. GT.map[Gr[pot][i].u][Gr[pot][i].v] = Gr[pot][i].weight ;
  68. }
  69. return ;
  70. }
  71. int cmp(const Node &a , const Node &b)
  72. {
  73. return a.number <b.number ;
  74. }
  75. int digit(int x )
  76. {
  77. // 计算位数
  78. int t = x ;
  79. int k = 0 ;
  80. while(t)
  81. {
  82. k++;
  83. t/=10 ;
  84. }
  85. return k ;
  86. }
  87. char *transtr(int n)
  88. {
  89. //转换成字符串
  90. //char t[MAX] ;
  91. char t[MAX] ;
  92. int i = 0 ,x = n ;
  93. while(x)
  94. {
  95. t[digit(n) - i-1] = (x%10) + '0' ;
  96. x/=10 ;
  97. i++;
  98. }
  99. return t ;
  100. }
  101. void Read(Node Place[] ,int n ,int e)
  102. {
  103. // 读取数据
  104. FILE *fp ;
  105. fp = fopen(path,"r");
  106. if(fp == NULL)
  107. {
  108. perror("fopen\n") ;
  109. exit(-1) ;
  110. }
  111. for(int i = 1 ; i<=n ; i++)
  112. {
  113. fscanf(fp,"%s %d",Place[i].PlaceName,&Place[i].number);
  114. int d = digit(Place[i].number) ;
  115. char Tmp[MAX] = "000";
  116. if(d==1)
  117. {
  118. strcpy(Place[i].PlaceNum,transtr(Place[i].number)) ;
  119. strcat(Tmp,Place[i].PlaceNum) ;
  120. strcpy(Place[i].PlaceNum,Tmp) ;
  121. }
  122. else if(d==2)
  123. {
  124. char Tmp[MAX] = "00";
  125. strcpy(Place[i].PlaceNum,transtr(Place[i].number)) ;
  126. strcat(Tmp,Place[i].PlaceNum) ;
  127. strcpy(Place[i].PlaceNum,Tmp) ;
  128. }
  129. else if(d==3)
  130. {
  131. char Tmp[MAX] = "0";
  132. strcpy(Place[i].PlaceNum,transtr(Place[i].number)) ;
  133. strcat(Tmp,Place[i].PlaceNum) ;
  134. }
  135. }
  136. return ;
  137. }
  138. void MAtToList(MatGraph g , AdjGraph *&G)
  139. {
  140. //将邻接矩阵转换成邻接表
  141. ArcNode *p ; // 边节点
  142. G = (AdjGraph *)malloc(sizeof(AdjGraph)) ;
  143. for(int i = 1 ; i<=g.n ; i++)
  144. {
  145. G->adjlist[i].fitstarc = NULL ;
  146. }
  147. for(int i = 1 ; i<= g.n ; i++)
  148. {
  149. for(int j = g.n ; j >=1 ; j--)
  150. {
  151. if(g.map[i][j]!= 0 && g.map[i][j] !=inf )
  152. {
  153. p = (ArcNode *)malloc(sizeof(ArcNode)) ;
  154. p->adjvex = j ;
  155. p->weight = g.map[i][j] ;
  156. p->nextarc = G->adjlist[i].fitstarc ;
  157. G->adjlist[i].fitstarc = p ;
  158. }
  159. }
  160. }
  161. G->n = g.n ;
  162. G->e = g.e ;
  163. return ;
  164. }
  165. int DispAdj(AdjGraph *G )
  166. {
  167. // 输出邻接表
  168. ArcNode *p ;
  169. int count = 0 ;
  170. for(int i = 1 ; i <=G->n ; i++ )
  171. {
  172. p = G->adjlist[i].fitstarc ;
  173. printf("%3d: " ,i ) ;
  174. while(p!=NULL )
  175. {
  176. printf("%3d[%d]-> ", p->adjvex , p->weight ) ;
  177. p = p->nextarc ;
  178. count++ ;
  179. }
  180. printf(" ^ \n") ;
  181. }
  182. return count;
  183. }
  184. BSTNode *SearchBST(BSTNode *bt , int k )
  185. {
  186. // 在二叉搜素树中查找 编号为k 的节点
  187. // return 节点的地址
  188. if(bt == NULL || bt->infor.number == k )
  189. {
  190. return bt ;
  191. }
  192. if(k < bt->infor.number)
  193. {
  194. return SearchBST(bt->lchild , k) ;
  195. }
  196. else
  197. {
  198. return SearchBST(bt->rchild , k ) ;
  199. }
  200. }
  201. void TopSort(AdjGraph *G)
  202. {
  203. // 拓扑排序 ;
  204. int St[MAX] , top = -1 ;
  205. ArcNode * p ;
  206. for(int i = 1 ; i<=G->n ; i++)
  207. {
  208. G->adjlist[i].count = 0 ; // 初始化
  209. }
  210. for(int i = 1 ; i<=G->n ; i++)
  211. {
  212. p = G->adjlist[i].fitstarc ;
  213. while(p!=NULL)
  214. {
  215. G->adjlist[p->adjvex].count++ ;
  216. p = p->nextarc ;
  217. }
  218. }
  219. for(int i = 1 ; i <=G->n ; i++)
  220. {
  221. if(G->adjlist[i].count == 0 )
  222. {
  223. top++ ;
  224. St[top] = i ;
  225. }
  226. }
  227. int i , j ;
  228. while(top>-1)
  229. {
  230. i = St[top] ;
  231. top -- ;
  232. cout<<i<<" " ;
  233. p = G->adjlist[i].fitstarc ;
  234. while(p!=NULL)
  235. {
  236. j = p->adjvex ;
  237. G->adjlist[j].count -- ;
  238. if(G->adjlist[j].count ==0 )
  239. {
  240. top++ ;
  241. St[top] = j ;
  242. }
  243. p = p->nextarc ; // 下一个邻接点 ;
  244. }
  245. }
  246. }
  247. void DFS(AdjGraph *G , int v , Node Place[] ,BSTNode *bt )
  248. {
  249. // 深度优先搜素
  250. ArcNode *p ;
  251. BSTNode *Root ;
  252. vis[v] = 1 ;
  253. //printf("%d ",v);
  254. Root = SearchBST(bt,v) ;// 在二叉排序树中找到
  255. if(Root!=NULL)// 小心驶得万年船,不加会异常
  256. {
  257. // if(vis[p->adjvex] = 0 )
  258. cout<<Root->infor.PlaceName <<"-> " ;
  259. MapVex[++count1]= Root ;// 将DFS创建的节点依次加入到导游图中
  260. // 创建导游图,
  261. }
  262. p = G->adjlist[v].fitstarc ;
  263. while(p!=NULL)
  264. {
  265. if(vis[p->adjvex] == 0 )
  266. {
  267. vis[p->adjvex] = 1 ; //
  268. DFS(G,p->adjvex,Place,bt) ;
  269. //vis[p->adjvex] = 0 ; //
  270. }
  271. p = p->nextarc ;
  272. }
  273. }
  274. void Display(Node Place[] ,int n)
  275. {
  276. // 显示所有景点名字
  277. cout<<"景点名字\t 编号\n" ;
  278. for(int i = 1 ; i<=n ;i++)
  279. {
  280. printf("%8s\t%8s\n",Place[i].PlaceName,Place[i].PlaceNum);
  281. // cout<<Place[i].PlaceName<< "\t"<<Place[i].PlaceNum<<endl;
  282. Sleep(100);
  283. }
  284. }
  285. void CreadMat(MatGraph &Map , int n , int e)
  286. {
  287. // 创建邻接矩阵
  288. FILE *fp ;
  289. fp = fopen("edge.txt","r");
  290. for(int i = 1 ; i<=n ; i++)
  291. {
  292. for(int j = 1 ;j<=n ; j++)
  293. {
  294. Map.map[i][j] = inf ;
  295. if(i == j )
  296. Map.map[i][j] = 0 ;
  297. }
  298. }
  299. Map.n = n ;
  300. Map.e = e ;
  301. for(int i = 1 ; i<=e ;i++)
  302. {
  303. int u , v ,w ;
  304. fscanf(fp,"%d %d %d",&u,&v,&w);
  305. Map.map[u][v] = w ;// 无向图
  306. Map.map[v][u] = w ;
  307. }
  308. return ;
  309. }
  310. bool InsertBST(BSTNode *&bt , Node k )
  311. {
  312. // 二叉排序树插入节点
  313. if(bt==NULL)
  314. {
  315. bt = (BSTNode*)malloc(sizeof(BSTNode)) ;
  316. bt->infor.number = k.number ;
  317. strcpy(bt->infor.PlaceName,k.PlaceName) ;
  318. strcpy(bt->infor.PlaceNum,k.PlaceNum);
  319. bt->lchild = NULL ;
  320. bt->rchild = NULL ;
  321. return true ;
  322. }
  323. else if (k.number == bt->infor.number)
  324. {
  325. return false ;
  326. }
  327. else if (k.number < bt->infor.number )
  328. {
  329. return InsertBST(bt->lchild , k) ;
  330. }
  331. else if (k.number > bt->infor.number )
  332. {
  333. return InsertBST(bt->rchild , k) ;
  334. }
  335. }
  336. BSTNode *CreatBST(Node Place[] , int n)
  337. {
  338. // 创建二叉排序树 ;
  339. BSTNode *bt = NULL;
  340. for(int i = 1; i <=n ; i++)
  341. {
  342. InsertBST(bt,Place[i]) ;
  343. }
  344. return bt ;
  345. }
  346. void Dijkstra(int cur,MatGraph Map,BSTNode *bt ,int End)
  347. {
  348. // 最短路Dijkstra 实现
  349. int n , e ;
  350. int Path[MAX] ;
  351. n = Map.n ;
  352. e = Map.e ;
  353. memset(vis,0,sizeof(vis)) ;
  354. memset(Path,0,sizeof(Path)) ;
  355. for(int i = 1 ; i<=n ;i++)
  356. {
  357. dis[i] = Map.map[cur][i] ;
  358. if(Map.map[cur][i] < inf)
  359. {
  360. Path[i] = cur ;
  361. }
  362. else
  363. {
  364. Path[i] = 0 ;
  365. }
  366. }
  367. vis[cur] = 1 ;
  368. Path[cur] = 0 ;
  369. for(int i = 1 ; i<n ; i++)
  370. {
  371. int minn = inf ;
  372. int u = -1 ;
  373. for(int j = 1 ; j<=n ; j++)
  374. {
  375. if(!vis[j] && dis[j]<minn)
  376. {
  377. minn = dis[j] ;
  378. u = j ;
  379. }
  380. }
  381. if(u !=-1)
  382. {
  383. vis[u] = 1 ;
  384. for(int v = 1 ; v <=n; v++)
  385. {
  386. if(Map.map[u][v]<inf && vis[v]== 0)
  387. {
  388. if(dis[v] > dis[u]+Map.map[u][v])
  389. {
  390. dis[v] = dis[u] + Map.map[u][v] ;
  391. Path[v] = u ;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. BSTNode *pfind1 ,*pfind2,*pfind3;
  398. int pre ;
  399. for(int i=1;i<=n;i++)//输出结果和最短路径
  400. {
  401. pfind1 = SearchBST(bt,cur) ;
  402. pfind2 = SearchBST(bt,i) ;
  403. if(pfind1 && pfind2)
  404. {
  405. if(End == pfind2->infor.number)
  406. {
  407. printf("%s 到 %s的最短距离为 ",pfind1->infor.PlaceName,pfind2->infor.PlaceName);
  408. printf("%d m\n",dis[i]); //打印结果
  409. pre = Path[i];
  410. printf("路径:%d",i);
  411. }
  412. while(pre!=0) //继续找前趋顶点
  413. {
  414. pfind3 = SearchBST(bt,pre) ;
  415. if(pfind1)
  416. {
  417. printf("<——%s",pfind3->infor.PlaceName);
  418. pre=Path[pre];
  419. }
  420. else
  421. exit(0) ;
  422. }
  423. }
  424. else
  425. {
  426. cout<<"输入错误 "<<endl;
  427. exit(0) ;
  428. }
  429. }
  430. return ;
  431. }
  432. void Prim(MatGraph Map ,int cur ,BSTNode *bt)
  433. {
  434. // 最小生成树
  435. int lowcost[MAX] ;
  436. int MIN ;
  437. int closet[MAX] , i , j , k ;
  438. cout<<"道路修建规划 : "<<endl;
  439. for( i = 1 ; i<=Map.n ; i++)
  440. {
  441. //cout<<Map.map[cur][i]<<" " ;
  442. lowcost[i] = Map.map[cur][i] ;
  443. closet[i] = cur ;
  444. }
  445. for( i = 1 ; i<Map.n ; i++)
  446. {
  447. MIN = inf ;
  448. for(j = 1 ; j<=Map.n ; j++)
  449. if(lowcost[j]!=0 && lowcost[j] <MIN)
  450. {
  451. MIN = lowcost[j] ;
  452. k = j ;
  453. }
  454. //printf("(%d ,%d) : %d \n ",closet[k],k ,MIN) ;
  455. BSTNode *s = SearchBST(bt,closet[k]) ;
  456. BSTNode *sz = SearchBST(bt,k) ;
  457. if( s!=NULL && sz !=NULL)
  458. {
  459. cout<<s->infor.PlaceName <<" - "<<sz->infor.PlaceName <<endl ;
  460. }
  461. lowcost[k] = 0 ;
  462. for(int j = 1 ;j <=Map.n ; j++)
  463. {
  464. if(lowcost[j] !=0 && Map.map[k][j]<lowcost[j])
  465. {
  466. lowcost[j] = Map.map[k][j] ;
  467. closet[j] = k ;
  468. }
  469. }
  470. }
  471. }
  472. int Find(char *a, Node M[],int n )
  473. {
  474. //查找
  475. int i ;
  476. bool find = false ;
  477. for( i = 1 ; i <=n ; i++)
  478. {
  479. if(strcmp(a,M[i].PlaceName)==0)
  480. {
  481. find = true ;
  482. break ;
  483. }
  484. }
  485. return find?M[i].number:-1;
  486. }
  487. void InOrder(BSTNode *bt )
  488. {
  489. // 中序
  490. if(bt!=NULL)
  491. {
  492. InOrder(bt->lchild) ;
  493. cout<<bt->infor.number <<" " <<bt->infor.PlaceName <<" "<<bt->infor.PlaceNum <<endl ;
  494. InOrder(bt->rchild) ;
  495. }
  496. return ;
  497. }
  498. void PageInfor()
  499. {
  500. system("color A") ;
  501. cout<<"\t\t\t *********************************************"<<endl;
  502. cout<<"\t\t\t * *"<<endl;
  503. cout<<"\t\t\t * *"<<endl;
  504. cout<<"\t\t\t *\t 景区旅游信息管理系统 *"<<endl ;
  505. cout<<"\t\t\t * 烟台山景区 *"<<endl;
  506. cout<<"\t\t\t * *"<<endl;
  507. cout<<"\t\t\t * *"<<endl;
  508. cout<<"\t\t\t *\t"<<" ☆"<<" 1 创建景区景点分布图 ☆ *"<<endl;
  509. cout<<"\t\t\t * *"<<endl;
  510. cout<<"\t\t\t *\t"<<" ☆"<<" 2 输出景区景点分布图 ☆ *"<<endl;
  511. cout<<"\t\t\t * *"<<endl;
  512. cout<<"\t\t\t *\t"<<" ☆"<<" 3 输出导游路线 ☆ *"<<endl;
  513. cout<<"\t\t\t * *"<<endl;
  514. cout<<"\t\t\t *\t"<<" ☆"<<" 4 输出最佳导游路线 ☆ *"<<endl;
  515. cout<<"\t\t\t * *"<<endl;
  516. cout<<"\t\t\t *\t"<<" ☆"<<" 5 输出最短路径 ☆ *"<<endl;
  517. cout<<"\t\t\t * *"<<endl;
  518. cout<<"\t\t\t *\t"<<" ☆"<<" 6 输出道路修建规划图 ☆ *"<<endl;
  519. cout<<"\t\t\t * *"<<endl;
  520. cout<<"\t\t\t *\t"<<" ☆"<<" 7 退出系统 ☆ *"<<endl;
  521. cout<<"\t\t\t * *"<<endl;
  522. cout<<"\t\t\t * *"<<endl;
  523. cout<<"\t\t\t *********************************************"<<endl;
  524. cout<<"功能选择 >> : ";
  525. }
  526. void DisplayMenu(int n ,int e )
  527. {
  528. TorNode Gr[MAX][MAX] ;
  529. MatGraph Map ,TMP ,TorMap;
  530. int TourMap[MAX][MAX];
  531. AdjGraph *G ;// 邻接表
  532. Node Place[MAX] ; // 所有的景点信息
  533. char start[MAX] ,end[MAX] ; // 起点和终点
  534. BSTNode *bt ; // 二叉排序树根节点
  535. cout<<endl<<endl;
  536. int num ;
  537. Read(Place,n,e) ; // 读入数据
  538. PageInfor() ; // 显示页面信息
  539. while(cin >> num && num!=7)
  540. {
  541. if(num == 1 )
  542. {
  543. CreadMat(Map,n,e) ;
  544. cout<<"地图创建成功 "<<endl;
  545. }
  546. else if(num == 2 )
  547. {
  548. // 显示景点图
  549. //Display(Place,n) ;
  550. cout<<"☆所有景点信息☆ \n";
  551. cout<<"景点名字\t 编号\n" ;
  552. for(int i = 1 ; i <=n ; i++)
  553. {
  554. cout<<Place[i].PlaceName<< " : "<<Place[i].number <<" : "<<Place[i].PlaceNum<<endl;
  555. }
  556. cout<<"景区地图 "<<endl ;
  557. for(int i = 1 ; i<= n ; i++)
  558. {
  559. cout<<" "<<i ;
  560. }
  561. cout<<endl;
  562. int k = 1 ;
  563. for(int i = 1 ; i <=n ; i++)
  564. {
  565. cout<<k++ <<" ";
  566. for(int j = 1 ; j<=n ; j++)
  567. {
  568. if(Map.map[i][j] == inf )
  569. {
  570. cout<<"∞"<<" " ;
  571. }
  572. else
  573. {
  574. printf("%d ",Map.map[i][j]);
  575. }
  576. }
  577. cout<<endl ;
  578. }
  579. cout<<endl ;
  580. }
  581. else if(num == 3 )
  582. {
  583. // 输出所有的旅游路线 ;
  584. bt = CreatBST(Place,n); // 创建二叉排序树
  585. cout<<"所有景点如下 : "<<endl ;
  586. InOrder(bt) ;// 中序遍历二叉树
  587. cout<<endl;
  588. MAtToList(Map ,G) ; // 转化成邻接表
  589. //DispAdj(G) ;
  590. //cout<<"dfs "<<endl ;
  591. int v = 2 ;
  592. printf("所有的导游路线 : \n" ) ;
  593. cout<<endl ;
  594. int num ;
  595. for(int i = 1 ; i<=n; i++)
  596. {
  597. cout<< "方案 "<<i<<" : \n " ;
  598. memset(vis,0,sizeof(vis)) ;
  599. memset(MapVex,0,sizeof(MapVex) ) ;
  600. DFS(G,i,Place,bt) ;
  601. count1 = 0 ;
  602. cout<<endl<<endl ;
  603. for(int j = 1 ; j<=n ; j++)
  604. {
  605. int u = MapVex[j]->infor.number ;
  606. TourMap[i][j] = u ;
  607. }
  608. }
  609. }
  610. else if (num == 4 )
  611. {
  612. TorMap.e = e ;
  613. TorMap.n = n ;
  614. cout<<endl;
  615. int StrageWeight[MAX][MAX] ;
  616. for(int i = 1 ;i <=n ;i++)
  617. {
  618. for(int j = 1 ;j <=n ;j++)
  619. {
  620. Gr[i][j].u = TourMap[i][j] ;// 起点,
  621. Gr[i][j].v = TourMap[i][j+1] ;
  622. Gr[i][j].weight = Map.map[TourMap[i][j]][TourMap[i][j+1]] ;
  623. //StrageWeight[i][j] = Map.map[TourMap[i][j]][TourMap[i][j+1]] ;
  624. }
  625. }
  626. // 见图
  627. MatGraph GT[20] ; // 导游路线图
  628. for(int i = 1 ; i<=n ;i++)
  629. CreatMatGragh(GT[i],n,e,i,Gr) ;
  630. int number ;
  631. int edgenum[MAX ] ;
  632. int ed = 0 ;
  633. for(int k = 1 ; k <=n ;k++)
  634. {
  635. for(int i = 1 ; i <= n ;i++)
  636. {
  637. for(int j = 1 ; j<=n ;j++)
  638. {
  639. if(GT[k].map[i][j]!=inf)
  640. {
  641. edgenum[k]++ ;
  642. }
  643. }
  644. }
  645. }
  646. for(int i = 1 ; i<=n ; i ++)
  647. {
  648. if(edgenum[i] == n-1)
  649. {
  650. number = i ; // 找到回路图 ;
  651. break ;
  652. }
  653. }
  654. cout<<" 最佳导游路线 "<<endl ;
  655. for(int i = 1 ;i <=n ; i++)
  656. {
  657. // 二叉搜索树,依次输出景点
  658. BSTNode *r = SearchBST(bt,TourMap[number][i]); // 查找最佳路线图
  659. cout<<r->infor.PlaceName ;
  660. if(i!=n)
  661. cout<<" -> ";
  662. }
  663. cout<<endl ;
  664. }
  665. else if (num == 5 )
  666. {
  667. bt = CreatBST(Place,n);
  668. BSTNode *pfind1 ,*pfind2 ;
  669. cout<<endl;
  670. Display(Place,n) ;
  671. cout<<endl;
  672. printf("输入起点景点 \n");
  673. cin >> start ;
  674. printf("输入终点景点 \n") ;
  675. cin >>end ;
  676. int Find_Start_Num = Find(start,Place,Map.n) ;
  677. int Find_End_Num = Find(end,Place,Map.n) ;
  678. pfind1 = SearchBST(bt,Find_Start_Num) ;//顶点
  679. pfind2 = SearchBST(bt,Find_End_Num) ; // 终点
  680. if(!pfind1 && !pfind2)
  681. exit(ERROR) ;
  682. else
  683. cout<<pfind1->infor.PlaceName << " - > " <<pfind2->infor.PlaceName <<endl;
  684. if(Find_Start_Num != -1 && Find_End_Num != -1)
  685. {
  686. Dijkstra(Find_Start_Num,Map,bt,Find_End_Num) ;
  687. }
  688. else
  689. {
  690. printf("输入错误 \n");
  691. exit(-1) ;
  692. }
  693. }
  694. else if (num == 6 )
  695. {
  696. bt = CreatBST(Place,n);
  697. Prim(Map ,1,bt );
  698. }
  699. else if (num == 7 )
  700. { // 终止程序
  701. cout<<"退出系统成功 "<<endl ;
  702. exit(0) ;
  703. }
  704. system("pause") ;
  705. PageInfor() ;
  706. }
  707. return ;
  708. }
  709. int main()
  710. {
  711. int n = 13 ;
  712. int e = 14 ;
  713. DisplayMenu(n,e ) ;
  714. return 0 ;
  715. }

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/430823
推荐阅读
相关标签
  

闽ICP备14008679号