c++实现图的操作
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
c++实现图的基本操作
#include
using namespace std;
typedef char VertexType;
#include "Graph.h"
#include "UDGraph.h"
#include "UNGraph.h"
#include "DGraph.h"
#include "DNGraph.h"
void ShowMainMenu()
{
cout<<"\n";
cout<<" ***************图的基本操作及应用******************\n"; cout<<" * 1 无向图的基本操作及应用*\n";
cout<<" * 2 无向网的基本操作及应用*\n";
cout<<" * 3 有向图的基本操作及应用*\n";
cout<<" * 4 有向网的基本操作及应用*\n";
cout<<" * 5 退出*\n";
cout<<" ***************************************************\n"; }
void UDG()
{
MGraph MG;
ALGraph ALG;
int n;
do
{
cout<<"\n";
cout<<" ***************无向图的基本操作及应用***************\n"; cout<<" * 1 创建无向图的邻接矩阵*\n";
cout<<" * 2 创建无向图的邻接表*\n";
cout<<" * 3 无向图的深度优先遍历*\n";
cout<<" * 4 无向图的广度优先遍历*\n";
cout<<" * 5 退出*\n";
cout<<" *************************************************\n"; cin>>n;
switch(n){
case 1:
CreatUDG_M(MG);
break;
case 2:
CreatUDG_ALG(ALG);
dispgraph(ALG);
break;
case 3:
CreatUDG_ALG(ALG);
dfstraverse(ALG);
break;
case 4:
CreatUDG_M(MG);
BFSTraver(MG);
break;
default:
if (n!=5)
cout<<"错误,重新输入\n";
}
}while(n!=5);
}
void UDN()
{
MGraph MG;
ALGraph ALG;
int n;
do{
cout<<"\n";
cout<<" ***************无向网的基本操作及应用***************\n"; cout<<" * 1 创建无向网的邻接矩阵*\n";
cout<<" * 2 创建无向网的邻接表*\n";
cout<<" * 3 prim算法求最小生成树*\n";
cout<<" * 4 kraskal算法求最小生成树*\n";
cout<<" * 5 退出*\n";
cout<<" ****************************************************\n"; cin>>n;
switch(n){
case 1:
CreateUDN_M(MG);
break;
case 2:
CreateUDN(ALG);
dispUDN(&ALG);
break;
case 3:
CreateUDN_M(MG);
prim(MG);
break;
case 4:
CreateUDN_M(MG);
Kruskal(MG);
break;
default:
if (n!=5)
cout<<"错误,重新输入\n";
}
}while(n!=5);
}
void DG()
{
MGraph MG;
ALGraph ALG;
int n;
do
{
cout<<"\n";
cout<<" ***************有向图的基本操作及应用***************\n"; cout<<" * 1 创建有向图的邻接矩阵*\n";
cout<<" * 2 创建有向图的邻
接表*\n";
cout<<" * 3 拓扑排序*\n";
cout<<" * 4 退出*\n";
cout<<" ****************************************************\n"; cin>>n;
switch(n){
case 1:
CreatDG_M(MG);
break;
case 2:
CreatDG_ALG(ALG);
dispgraph(ALG);
break;
case 3:
CreatDG_ALG(ALG);
TopologicalSort(ALG);
break;
default:
if (n!=4)
cout<<"错误,重新输入\n";
}