导游系统-------图的最短路径算法导游系统算法核心部分//图的建立//和从莫一顶点到其他所有顶点的最段路径运行时输入 :边的个数:顶点的内容:----------字符串形式每条边的两个顶点和权值#include<iostream>#include<>#include<fstream>#include<>usingnamespacestd;constintMAX=30;typedefstringVT;typedefintET;constfloatBIGEST=; classCGraph{ public: intShortPath(intstart,boolPath[][MAX]); voidCreateGraph(); boolIsEmpty(); voidClearGraph(); voidPrintGraph(); intGetVNum(); CGraph(); ~CGraph(); protected: intVNum;//顶点的个数 intENum;//边数 ET Edge[MAX*2];//边的集合 VT Vertex[MAX];//顶点的集合 intMatrix[MAX][MAX];//顶点间的关系 }; //类的定义voidCGraph::CreateGraph(){//创建图 ifstreamInFile; charFileName[50]; cout<<"EnterInputFileName:"; cin>>FileName; cout<<endl; (FileName); if(!InFile) { cerr<<"canontopenfile"; return; } InFile>>VNum>>ENum; cout<<"theVnumis"<<VNum<<"theEnumis"<<ENum<<endl; for(intindex=0;index<VNum;index++) { InFile>>Vertex[index]; cout<<index<<"的顶点的值是"<<Vertex[index]<<endl; } //初始化句阵 for(inti=0;i<MAX;i++) for(intj=0;j<MAX;j++) Matrix[j]=0; for(intindex=0;index<ENum;index++) { inta,b,c; InFile>>a>>b>>c; Matrix[a]=c; Matrix[a]=c; //显示两个定点及其权值 cout<<a<<" "<<b<<" "<<c<<endl;
导游系统-------图的最短路径算法 来自淘豆网www.taodocs.com转载请标明出处.