idk why these stuffs get stashed for so long and I didn't ever commit them
This commit is contained in:
132
OrigFiles/6-图/6-MGraph(无向图邻接矩阵存储)/Mgraph.cpp
Normal file
132
OrigFiles/6-图/6-MGraph(无向图邻接矩阵存储)/Mgraph.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
#include<string>
|
||||
#include "LinkQueue.h"
|
||||
#include "Mgraph.h"
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
|
||||
|
||||
|
||||
// 无向图
|
||||
|
||||
void DispMenu()
|
||||
{
|
||||
cout<<"请选择你要的操作"<<endl;
|
||||
cout<<" 1. 建立图"<<endl;
|
||||
cout<<" 2. 返回顶点在图中的位置"<<endl;
|
||||
cout<<" 3. 返回某位置的顶点的值"<<endl;
|
||||
cout<<" 4. 修改顶点值"<<endl;
|
||||
cout<<" 5. 增加新顶点"<<endl;
|
||||
cout<<" 6. 删除顶点弧"<<endl;
|
||||
cout<<" 7. 增添边"<<endl;
|
||||
cout<<" 8. 删除边"<<endl;
|
||||
cout<<" 9. 从第一个顶点出发深度优先遍历图"<<endl;
|
||||
cout<<"10. 从第一个顶点广度优先遍历图"<<endl;
|
||||
cout<<"11. 显示图"<<endl;
|
||||
cout<<" 0. 退出"<<endl;
|
||||
}
|
||||
|
||||
bool visited[MAX_VEXNUM]={false};
|
||||
|
||||
void main()
|
||||
{
|
||||
char u,v;
|
||||
int k;
|
||||
MGraph<char> G;
|
||||
int choice;
|
||||
do
|
||||
{
|
||||
DispMenu();
|
||||
cin>>choice;
|
||||
switch(choice)
|
||||
{
|
||||
case 1:
|
||||
CreateUDN(G);
|
||||
cout<<endl;
|
||||
cout<<"创建的图为:"<<endl;
|
||||
DispG(G);
|
||||
break;
|
||||
case 2:
|
||||
cout<<"请输入您要的所要查询位置的顶点的名称: ";
|
||||
cin>>u;
|
||||
k=LocateVex(G,u);
|
||||
if(k!=-1)
|
||||
cout<<"顶点"<<u<<"在图中的位置为: "<<k<<endl;
|
||||
else
|
||||
cout<<"顶点"<<u<<"不存在!"<<endl;
|
||||
cout<<endl;
|
||||
break;
|
||||
case 3:
|
||||
int index;
|
||||
cout<<"请输入您要的所要查询顶点的位置: ";
|
||||
cin>>index;
|
||||
if(GetVex(G,index,v))
|
||||
cout<<"位置为"<<index<<"的顶点为: "<<v<<endl;
|
||||
else
|
||||
cout<<"第"<<index<<"顶点不存在!"<<endl;
|
||||
cout<<endl;
|
||||
break;
|
||||
case 4:
|
||||
cout<<"请输入要更改的顶点值: ";
|
||||
cin>>u;
|
||||
cout<<"请输入更改后顶点的值: ";
|
||||
cin>>v;
|
||||
PutVex(G,u,v);
|
||||
cout<<"顶点值修后的图为“"<<endl;
|
||||
DispG(G);
|
||||
cout<<endl;
|
||||
break;
|
||||
case 5:
|
||||
cout<<"请输入要增加的顶点的值: ";
|
||||
cin>>v;
|
||||
InsertVex(G,v);
|
||||
cout<<"插入顶点和相应边后的图为“"<<endl;
|
||||
DispG(G);
|
||||
cout<<endl;
|
||||
break;
|
||||
case 6:
|
||||
cout<<"请输入要删除的顶点的值:";
|
||||
cin>>v;
|
||||
DeleteVex(G,v);
|
||||
cout<<"顶点删除后的图为“"<<endl;
|
||||
DispG(G);
|
||||
cout<<endl;
|
||||
break;
|
||||
case 7:
|
||||
cout<<"请输入要增添边的顶相邻两顶点";
|
||||
cin>>u>>v;
|
||||
InsertArc(G,u,v);
|
||||
cout<<"插入边后的图为“"<<endl;
|
||||
DispG(G);
|
||||
cout<<endl;
|
||||
break;
|
||||
case 8:
|
||||
cout<<"请输入删除的边相邻两顶点: ";
|
||||
cin>>u>>v;
|
||||
DeleteArc(G,u,v);
|
||||
cout<<"顶点边后的图为“"<<endl;
|
||||
DispG(G);
|
||||
cout<<endl;
|
||||
break;
|
||||
case 9:
|
||||
cout<<"从第一个顶点出发深度优先遍历图的序列为: "<<endl;
|
||||
DFSTraverse(G);
|
||||
cout<<endl;
|
||||
break;
|
||||
case 10:
|
||||
cout<<"从第一个顶点出发广度优先遍历图的序列为: "<<endl;
|
||||
BFSTraverse(G);
|
||||
cout<<endl;
|
||||
break;
|
||||
case 11:
|
||||
DispG(G);
|
||||
cout<<endl;
|
||||
break;
|
||||
case 0:
|
||||
cout<<"结束运行,Bye-Bye!"<<endl;
|
||||
break;
|
||||
default:
|
||||
cout<<"选择不合理,请重选!"<<endl;
|
||||
}//case
|
||||
}while(choice!=0);
|
||||
}//main
|
||||
|
||||
Reference in New Issue
Block a user