#include<stdio.h>
//#include<malloc.h>
#define N 50
#define MAx 1000;
typedef struct
{ int vertex;
}vertrxtype;
typedef struct
{ int adj;
} arctype;
typedef struct
{ int vex[N];
int arcs[N][N];
int vexnum,arcnum;
}MGRAPH;
void creatgraph(MGRAPH *g)
{
int i,j,k,weight,n;
printf("请输入图的顶点数和边数\n");
scanf("%d,%d",&(*g).vexnum,&(*g).arcnum);
n=(*g).vexnum;
for(i=0;i<n;i++)(*g).vex[i]=i;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
(*g).arcs[i][j]=0;
}
for(k=0;k<(*g).arcnum;k++)
{
printf("请输入一条边的两个端点的序号及其上的权值\n");
scanf("%d,%d,%d",&i,&j,&weight);
(*g).arcs[i][j]=weight;
(*g).arcs[j][i]=weight;
}
for(i=0;i<n;i++)
{ for(j=0;j<n;j++)
printf("%d",(*g).arcs[i][j]);
printf("\n");
}
}
void main()
{
creatgraph();
}程序到底错了那里呢?被数据结构搞得很烦哪!!!
//#include<malloc.h>
#define N 50
#define MAx 1000;
typedef struct
{ int vertex;
}vertrxtype;
typedef struct
{ int adj;
} arctype;
typedef struct
{ int vex[N];
int arcs[N][N];
int vexnum,arcnum;
}MGRAPH;
void creatgraph(MGRAPH *g)
{
int i,j,k,weight,n;
printf("请输入图的顶点数和边数\n");
scanf("%d,%d",&(*g).vexnum,&(*g).arcnum);
n=(*g).vexnum;
for(i=0;i<n;i++)(*g).vex[i]=i;
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
(*g).arcs[i][j]=0;
}
for(k=0;k<(*g).arcnum;k++)
{
printf("请输入一条边的两个端点的序号及其上的权值\n");
scanf("%d,%d,%d",&i,&j,&weight);
(*g).arcs[i][j]=weight;
(*g).arcs[j][i]=weight;
}
for(i=0;i<n;i++)
{ for(j=0;j<n;j++)
printf("%d",(*g).arcs[i][j]);
printf("\n");
}
}
void main()
{
creatgraph();
}程序到底错了那里呢?被数据结构搞得很烦哪!!!