#include <stdio.h> #include <stdlib.h> #define MaxSize 20 typedef int VertexType; typedef int EdgeType; typedef int Elem ; typedef struct{ //邻接矩阵 VertexType Vex[MaxSize]; EdgeType Edge[MaxSize][MaxSize]; int vernum,edgenum; }MGraph; void Create(MGraph &G) { int i,j; G.edgenum=0; printf("输入顶点数\n"); scanf("%d",&G.vernum); printf("输入顶点表\n"); for(i=0;i<G.vernum;i++) scanf("%d",&G.Vex[i]); printf("输入矩阵\n"); for(i=0;i<G.vernum;i++) for(j=0;j<G.vernum;j++) { scanf("%d",&G.Edge[i][j]); G.edgenum++; } G.edgenum/=2; } void display(MGraph G) { int i,j; printf("顶点表:\n"); for(i=0;i<G.vernum;i++) printf("%d ",G.Vex[i]); printf("\n"); for(i=0;i<G.vernum;i++) { for(j=0;j<G.vernum;j++) printf("%d ",G.Edge[i][j]); printf("\n"); } } void JudgeEL(MGraph G) { int i,j,degree,count=0; for(i=0;i<G.vernum;i++) { degree=0; for(j=0;j<G.vernum;j++) degree+=G.Edge[i][j]; if(degree%2!=0) count++; } if(count==2||count==0) printf("ExistEL"); else printf("NoExistEL"); } int main() { MGraph G; Create(G); display(G); printf("\n"); JudgeEL(G); return 0; }
标签:typedef,vernum,int,邻接矩阵,MaxSize,edgenum From: https://www.cnblogs.com/simpleset/p/17858090.html