【无标题】C++邻接矩阵建图与遍历图

【无标题】C++邻接矩阵建图与遍历图,第1张

#include
#include 
using namespace std;
#define MAX_VERTEX_NUM 100
#define MAX 100
typedef struct ArcCell{
	int adj;
}AdjMatrix[MAX_VERTEX_NUM][MAX_VERTEX_NUM];

typedef struct{
	char vexs[MAX_VERTEX_NUM];
	AdjMatrix arcs;
	int vexnum,arcnum;
}MGraph;

typedef struct{
	char visited[MAX];
}Recording;

int judge(MGraph G,char V){
	int count = 0;
	for(int i=0;i>G.vexnum; 
		cout<<"弧(边)数范围:0~"<>G.arcnum;
		if(G.arcnum<0||G.arcnum>G.vexnum*(G.vexnum-1)){
			cout<<"弧(边)数输入有误!"<>G.vexs[i];
		}
		for(int i=0;i>V1;
			judge(G,V1);
			i = LocateVex(G,V1);
			cout<<"输入第"<>V2;
			judge(G,V2);
			j = LocateVex(G,V2);
			if(V1==V2){
				cout<<"不能连接相同点!请重新输入"<>G.vexnum; 
		cout<<"弧(边)数范围:0~"<>G.arcnum;
		if(G.arcnum<0||G.arcnum>G.vexnum*(G.vexnum-1)){
			cout<<"弧(边)数输入有误!"<>G.vexs[i];
		}
		for(int i=0;i>V1;
			judge(G,V1);
			i = LocateVex(G,V1);
			cout<<"输入第"<>V2;
			judge(G,V2);
			j = LocateVex(G,V2);
			cout<<"输入第"<>W;
			if(G.arcs[i][j].adj != 0){
				cout<<"此弧(边)已经连接,请重新输入"<>G.vexnum; 
		cout<<"弧(边)数范围:0~"<<0.5*G.vexnum*(G.vexnum-1)<>G.arcnum;
		if(G.arcnum<0 || G.arcnum>0.5*G.vexnum*(G.vexnum-1)){
			cout<<"弧(边)数输入有误!"<>G.vexs[i];
		}
		for(int i=0;i>V1;
			judge(G,V1);
			i=LocateVex(G,V1);
			cout<<"输入第"<>V2;
			judge(G,V2);
			j=LocateVex(G,V2);
			G.arcs[i][j] = G.arcs[j][i];
			if(G.arcs[i][j].adj == 1){
				cout<<"此弧(边)已经连接,请重新输入"<>G.vexnum; 
		cout<<"弧(边)数范围:0~"<<0.5*G.vexnum*(G.vexnum-1)<>G.arcnum;
		if(G.arcnum<0 || G.arcnum>0.5*G.vexnum*(G.vexnum-1)){
			cout<<"弧(边)数输入有误!"<>G.vexs[i];
		}
		for(int i=0;i>V1;
			judge(G,V1);
			i=LocateVex(G,V1);
			cout<<"输入第"<>V2;
			judge(G,V2);
			j=LocateVex(G,V2);
			cout<<"输入第"<>W;
			G.arcs[i][j] = G.arcs[j][i];
			if(G.arcs[i][j].adj != 0){
				cout<<"此弧(边)已经连接,请重新输入"<>i;
	switch(i){
		case 1:
			return CreateDG(G);
		case 2:
			return CreateDN(G);
		case 3:
			return CreateUDG(G);
		case 4:
			return CreateUDN(G);
		default:
			cout<<"错误!请重新输入"<>node;
	judge(G,node);
	int nodes;
	int keepnum = 0;
	nodes = LocateVex(G,node);
	for(int v=0;v>i;
	switch(i){
		case 1:
			return keep(G,R);
		case 2:
			return BFSTraverse(G,R);
		default:
			cout<<"错误!请重新输入"<

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/langs/1325919.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-12
下一篇 2022-06-12

发表评论

登录后才能评论

评论列表(0条)