文档详情

火车路线查询最短路径数据结构C.doc

发布:2019-01-28约6.35千字共12页下载文档
文本预览下载声明
includeiostream #include string includeiomanip using namespace std; const int MAXVertices = 20; const int MAXweight = 6000; struct Vertex { string city; }; class Graph { public: /*录入信 /*录入信 /*添加信 /*修改信 八删除信 /*显示信 /*单个最短 /*所有最短 void input(); 息、*/ void add(); 息、*/ void change(); 息*/ void del(); 息*/ void show(); 息*/ void select_pathl(); 路程查询*/ void select_path2(); 路程查询勺 private: int Edge[M AX Vertices] [MAXVertices]; int numE,numV; Vertex VerticesfM AX Vertices]; }; Graph: :Graph()/*构造函数初始化*/ { for(int i=O;iMAXVertices;i++) Vertices[i].city=O; for(i=0;iMAXVertices;i++) for(int j=O;jMAXVertices;j++) { if(i==j) Edge[i][j]=O; else Edgefi] [j]=M AX weight; numE=O; numV=O; void Graph::input()/*录入信息*/ int i; int vi; int vj; int 1; cout?输入路径的条数:”; cin? numE; COUt?H输入站点个数:”; cin?numV; cout?输入站点名称:?endl; for(i=0;inumV;i++) { cout?i+lvv:; cin?Verticesfi].city; for(i=0;inumE;i++) { cout?H输入站点i到站点j的路径的长度(i,j:站点前的序号):H?endl; cout?站点 i: cin?vi; cout?站点j: cin?vj; cout?n路径长度(千米):”; cin?l; Edge[vi-l][vj-l]=l; Edge[vj-l][vi-l]=l; } cout?录入完成 M?endl; } void Graph::add()/*添加信息*/ int i; int vi; int vj; inti; int x,y; cout?输入添加的路径的条数:”; cin?x; coutVV 输入添加的站点个数:”; cin?y; cout?n输入添加站点名称:” ?endl; for(i=0;iy;i++) { cout?numV+i+1 vv ” : ” ; cin?Vertices[numV+i].city; cout?H 添加成功!M?endl; } for(i=0;ix;i++) { coutvv“输入站点i到站点j的路径的长度(i,j:站点前的序号):,r?endl; cout?站点 i: ”; cin?vi; cout?站点j: ”; cin?vj; cout?n路径长度(千米):”; cin?l; Edge[vi-1 ] [vj-11=1; Edge[vj-l][vi-l]=l; cout?添加成功! H?endl; } numE=x+numE; numV=y+numV; } void Graph::change()/*修改信息*/ { string a; string c; int b=0; char e; char d; int x; inty; int f; cout?H是否修改站点名字(Y/N)M?endl; cin?e; if(e==,y,) { cout?n所有站点的名字:M?endl; for(int q=0;qnumV;q++) cout?setw(4)?q+l?,l.,,Vertices[q].city; } cout?endl; cout?n请输入要修改的站点名字:”; cin?a; for(int i=O;inumV;i++) if(Vertices[i].city==a) { cout?n请重新输入站点名字:”; cin?c; Verticesfi].city=c; b++; cout?修改成功!?endl; } if(b=O) cout?不存在该站点! vvendl; } cout?H是否修改站点距离(Y/N)M?endl; cin?d; if(d=y) { cout?n请输入要修改路线的站点序号vi:”; cin?x; cout
显示全部
相似文档