编写一个算法,完成无向图的邻接矩阵和邻接表的构造函数。在此基础上,完成图的深度优先和广度优先遍历算法。
#includetypedef char ElemType; #define MaxSize 10 typedef struct { int arc[MaxSize][MaxSize]; int vextexnum,arcnum; ElemType vertex[MaxSize]; }MGraph; bool visited[MaxSize]; bool visited1[MaxSize]; typedef struct ArcNode { int adjvex; struct ArcNode *next; }ArcNode; typedef struct VertexNode { ElemType vertex; ArcNode *firstedge; }VertexNode; typedef struct ALGraph { VertexNode adjlist[MaxSize]; int vextexnum,arcnum; }ALGraph; void MGraph1(MGraph &g,ElemType a[],int n,int e) { g.vextexnum=n; g.arcnum=e; int i,j,k; for(i=0;i cin>>i>>j; g.arc[i][j]=1; g.arc[j][i]=1; } } void ALGraph1(ALGraph &g,ElemType a[],int n,int e) { g.vextexnum=n; g.arcnum=e; int i,j,k; ArcNode *s; for(i=0;i g.adjlist[i].vertex=a[i]; g.adjlist[i].firstedge=NULL; } for(k=0;k cin>>i>>j; s=new ArcNode; s->adjvex=j; s->next=g.adjlist[i].firstedge; g.adjlist[i].firstedge=s; } } void DispMat(MGraph &g) { int i,j; for(i=0;i for(j=0;j int i; ArcNode *p; for(i=0;i p=G.adjlist[i].firstedge; if(p!=NULL) cout< cout< adjvex<<" "; p=p->next; } cout< int j; cout< int j; int front,rear; int Q[MaxSize]; front=rear=-1; cout< v=Q[++front]; for(j=0;j if(g.arc[v][j]==1&&visited1[j]==0) { cout< MGraph g; ALGraph g1; ElemType a[]={'a','b','c','d'}; cout<<"请输入邻接矩阵的4条边两端的顶点:"<



