您好,欢迎访问三七文档
#includeiostream#includefstream#includestring#includeiomanip#defineNULL0typedefcharVertexType[20];//ÓÃÓÚ´æ´¢³ÇÊÐÃû#defineMaxVerNum30//½á¹¹ÌåÊý×éµÄ×î´óÁ¿#defineMaxCost1000000//×î´ó»¨·Ñ#defineMaxEdgeNum50//ÁÚ½Ó¾ØÕóµÄ×î´ó±ßÖµusingnamespacestd;typedefstruct{intdistance,cost,time;//¾àÀ룬»¨·Ñ£¬Ê±¼ä}EdgeType;typedefstruct{VertexTypevexs[MaxVerNum];//30¸ö³ÇÊÐEdgeTypeedges[MaxVerNum][MaxVerNum];//ÁÚ½Ó¾ØÕóintedgenum,vernum;//¶¥µãÊý£¬±ßÊý}Graph;//ÁÚ½Ó¾ØÕó½á¹¹ÌåtypedefstructNode{intdata;structNode*lcild,*rcild;}BiTNode,*Bitree;//¶þ²æÊ÷½á¹¹Ìåintmain()//Ö÷º¯Êý{voidKey();//ÃÜÂ뺯ÊývoidWindow1();//´°¿Úº¯Êý1voidWindow2();//´°¿Úº¯Êý2voidWindow3();//Í˳ö´°¿Ú½çÃ溯ÊývoidHand_Menu();//²Ëµ¥Ñ¡Ôñº¯ÊýWindow1();//½çÃæ´°¿Ú1Key();//ÃÜÂ뺯ÊýWindow2();//½çÃæ´°¿Ú2Hand_Menu();Window3();//Í˳ö´°¿Ú½çÃ溯Êýreturn0;}voidWindow1()//½øÈë´°¿Ú½çÃ溯Êý1{system(colore3);//ʹ½çÃæ΢»ÆÉ«cout¡î¡î¡î¡î¡î¡î¡î¡î¡î½»Í¨¹ÜÀíϵͳ¡î¡î¡î¡î¡î¡î¡î¡îendl;}voidWindow2()//½øÈë´°¿Ú½çÃ溯Êý2{system(color0f);system(cls);//½çÃæÑÕɫΪºÚÉ«»»Ò³cout¡î¡î¡î¡î¡î¡î¡î»¶Ó½øÈ뽻ͨ¹ÜÀíϵͳ¡î¡î¡î¡î¡î¡î¡îendlendl;}voidWindow3()//Í˳ö´°¿Ú½çÃæ{system(cls);system(colore4);//»»Ò³²¢Ê¹±³¾°ÑÕɫΪ»ÆÉ«×ÖÌåΪºìÉ«cout¡î¡î¡î¡î¡î¡î¡î¡î¡î¡îÍ˳ö½»Í¨¹ÜÀíϵͳ¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡îendlendl;cout¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¸ÐлÄúµÄʹÓáî¡î¡î¡î¡î¡î¡î¡î¡î¡î¡îendlendl;cout¡î¡îÖÆ×÷ÈË:±±»ªº½Ì칤ҵѧԺB08515°à½ð½¡¡î¡îendlendlendlendl;}//-----------------------------------------------------voidKey()//ÃÜÂ뺯Êý{stringkey;stringm;stringh;inta;ifstreaminput(e:\\key.txt,ios::in);//´ò¿ªÎļþif(input==0)//µÚÒ»´ÎʹÓÃʱ×Ô¶¯×°ÈëÃÜÂë{ofstreamout(e:key.txt,ios::out);stringd=dowhatyouwant;outd;out.close();coutÄúÊǵÚÒ»´ÎʹÓôËϵͳ,ÃÜÂëÊÇ:dowhatyouwantendl;cout½¨ÒéÄú½øÈëϵͳºóÁ¢¼´ÐÞ¸ÄÃÜÂë!endl;}input.close();ifstreamin(e:\\key.txt,ios::in);//´ò¿ªÎļþinm;//¶ÁÈëÎļþkey=m;in.close();end:;cout¡î¡î¡îÇëÊäÈëÃÜÂë:;cinh;if(key==h)key=m;else{coutÃÜÂë´íÎó,ÇëÖØвÙ×÷!endl;gotoend;}cout1ÐÞ¸ÄÃÜÂë2²»ÐÞ¸ÄÃÜÂëendl;cina;if(a==1){coutÐÂÃÜÂë:endl;cinkey;ofstreamout(e:\\key.txt,ios::out);outkey;out.close();return;}if(a==2)return;}//--------------------------------------------voidHand_Menu()//Ö÷½çÃæ²Ëµ¥{voidO_City();//µ½ÆäËûËùÓгÌÐòvoidR_City();//ÈÎÒâÁ½³ÇÊÐGraph*Create();//ÐÞ¸ÄÐÅÏ¢Graph*G;inti;for(;;){cout¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î½»Í¨¹ÜÀíϵͳ¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡îendl;cout¡î1Ò»¸ö³ÇÊе½ÁíÍâËùÓгÇÊÐ2ÈÎÒâÁ½¸ö³ÇÊÐ3ÐÞ¸ÄÐÅÏ¢4Í˳ö¡îendl;cout¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡îendl;cini;while(i1||i3){coutÑ¡Ôñ´íÎó!ÇëÖØÐÂÊäÈë1-3:endl;cini;}switch(i){case1:O_City();break;//µ½ÆäËûËùÓгÇÊÐcase2:R_City();break;//ÈÎÒâ³ÇÊÐcase3:G=Create();break;//ÐÞ¸ÄÐÅÏ¢case4:return;}}}//------------------------------------------------voidO_City()//Ò»³ÇÊе½ÁíÍâËùÓгÇÊÐ{Graph*Read();//¶ÁÎļþintMenu_Select();//·µ»Ø²Ëµ¥Ñ¡ÔñµÄÖµvoidShortestPath(Graph*g,intm,intn);//Ñ°ÕÒº¯ÊýGraph*g;g=Read();//¶ÁÈ¡ÐÅÏ¢VertexTypea;//´æ´¢Õ¾ÃûµÄ±äÁ¿intflag,i;for(;;){coutÊäÈëËùÔÚÕ¾:endl;for(;;)//Ñ°ÕÒÕ¾ÃûµÄÑ»·{cina;for(i=1;i=g-vernum;i++)if(strcmp(a,g-vexs[i])==0)//ÕÒµ½¸ÃÕ¾break;if(ig-vernum)//ûÓÐÕÒµ½coutÊäÈë´íÎó!ÖØÊäʼ·¢Õ¾:endl;elsebreak;}flag=1;while(flag){switch(Menu_Select())//Ñ¡Ôñ²Ëµ¥{case1:ShortestPath(g,i,1);break;//×î¶Ì¾àÀëcase2:ShortestPath(g,i,2);;break;//×î¶Ì»¨·Ñcase3:ShortestPath(g,i,3);break;//×î¶Ìʱ¼äcase4:flag=0;break;case5:return;}}}}//----------------------------------------------------voidR_City()//ÈÎÒâÁ½¸ö³ÇÊÐ{Graph*Read();//¶ÁÎļþvoidShortestPath_2(Graph*g,intP[MaxVerNum][MaxVerNum],intD[MaxVerNum][MaxVerNum],intp);voidPath(Graph*g,intP[MaxVerNum][MaxVerNum],intD[MaxVerNum][MaxVerNum],intm,intn,intp);intMenu_Select();Graph*g;g=Read();VertexTypea,b;inti,j,m,flag;intLP[MaxVerNum][MaxVerNum],LD[MaxVerNum][MaxVerNum];intCP[MaxVerNum][MaxVerNum],CD[MaxVerNum][MaxVerNum];intTP[MaxVerNum][MaxVerNum],TD[MaxVerNum][MaxVerNum];ShortestPath_2(g,LP,LD,1);ShortestPath_2(g,CP,CD,2);ShortestPath_2(g,TP,TD,3);for(;;){coutÊäÈëʼ·¢Õ¾:endl;for(;;){cina;for(i=1;i=g-vernum;i++)if(strcmp(a,g-vexs[i])==0)break;if(ig-vernum)coutÊäÈë´íÎó!ÇëÖØÊäʼ·¢Õ¾:endl;elsebreak;}coutÊäÈëÖÕµãÕ¾:endl;for(;;){cinb;for(j=1;j=g-vernum;j++)if(strcmp(b,g-vexs[j])==0)break;if(jg-vernum)coutÊäÈë´íÎóÇë!ÖØÊäÖÕµãÕ¾:endl;elsebreak;}//*/flag=1;while(flag){switch(m=Menu_Select()){case1:Path(g,LP,LD,i,j,1);break;case2:Path(g,CP,CD,i,j,2);break;case3:Path(g,TP,TD,i,j,3);break;case4:flag=0;break;case5:return;}}}}//-------------------------------------------------------intMenu_Select()//Ñ¡Ôñ²Ëµ¥·µ»ØÑ¡ÔñµÄÖµ{inti;cout¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î½»Í¨¹ÜÀíϵͳ¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡îendl;cout¡î1×î¶Ì·¾¶2×îÉÙ»¨·Ñ3×î¶Ìʱ¼ä4²éѯÆäËûÕ¾µã5·µ»ØÖ÷²Ëµ¥¡îendl;cout¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡î¡îendl;coutÑ¡Ôñ1-5:endl;cini;while(i1||i5){coutÊäÈë´íÎó,ÇëÖØÐÂÊäÈë1-5;cini;}returni;}//-----------------------------------------------------voidShortestPath(Graph*g,intm,intn)//Ò»¸ö³ÇÊе½ÆäËûµÄÑ°ÕÒ{//m±íʾµØµãintP[Ma
本文标题:交通图-c语言
链接地址:https://www.777doc.com/doc-7289205 .html