#include<stdio.h>
#include<stdlib.h>
#define MAXSIZE 30
typedef struct{
char rertex[MAXSIZE];
int edges[MAXSIZE][MAXSIZE];
}MGraph;
void CreatMGraph(MGraph *g,int e,int n){//图 边 顶点
int k,i,j;
printf("Input data of vertexs(0 ~ n-1):\n");
for(i=0;i<n;i++)
g->rertex[i]=i; //读顶点 可自行输入
for(i=0;i<n;i++)
for(j=0;j<n;j++)
g->edges[i][j]=0;
for(k=0;k<e;k++)
{
printf("Input edges of(i,j):");
scanf("%d,%d",&i,&j);
g->edges[i][j]=1;
g->edges[j][i]=1; //删除此句则成有向表
}
}
void main()
{
int n,e,i,j;
MGraph *g;
g=( MGraph *) malloc(sizeof(MGraph));
printf("Input edges and vertexs:");
scanf("%d%d",&e,&n);
CreatMGraph(g,e,n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d ",g->edges[i][j]);
printf("\n");
}
}
/*Input edges and vertexs:4 4
Input data of vertexs(0 ~ n-1):
Input edges of(i,j):0,1
Input edges of(i,j):0,3
Input edges of(i,j):1,3
Input edges of(i,j):1,2
0 1 0 1
1 0 1 1
0 1 0 0
1 1 0 0
Press any key to continue*/
#include<stdlib.h>
#define MAXSIZE 30
typedef struct{
char rertex[MAXSIZE];
int edges[MAXSIZE][MAXSIZE];
}MGraph;
void CreatMGraph(MGraph *g,int e,int n){//图 边 顶点
int k,i,j;
printf("Input data of vertexs(0 ~ n-1):\n");
for(i=0;i<n;i++)
g->rertex[i]=i; //读顶点 可自行输入
for(i=0;i<n;i++)
for(j=0;j<n;j++)
g->edges[i][j]=0;
for(k=0;k<e;k++)
{
printf("Input edges of(i,j):");
scanf("%d,%d",&i,&j);
g->edges[i][j]=1;
g->edges[j][i]=1; //删除此句则成有向表
}
}
void main()
{
int n,e,i,j;
MGraph *g;
g=( MGraph *) malloc(sizeof(MGraph));
printf("Input edges and vertexs:");
scanf("%d%d",&e,&n);
CreatMGraph(g,e,n);
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d ",g->edges[i][j]);
printf("\n");
}
}
/*Input edges and vertexs:4 4
Input data of vertexs(0 ~ n-1):
Input edges of(i,j):0,1
Input edges of(i,j):0,3
Input edges of(i,j):1,3
Input edges of(i,j):1,2
0 1 0 1
1 0 1 1
0 1 0 0
1 1 0 0
Press any key to continue*/