Status Create(ALGraph *G)
{
int i,j,k;
char v1[20],v2[20];
ArcNode *p,*q;
printf("请输入顶点数和边数:");
scanf("%d%d",&G->vertices,&G->arcnum);
for(i=0;i<G->vexnum;i++)
{
scanf("%s",G->vertices[i].data);
G->vertices[i].firstarc=NULL;
}
for(k=0;k<G->arcnum;k++)
{
scanf("%s%s",v1,v2);
i=LocateVex(*G,v1);
j=LocateVex(*G,v2);
p=(ArcNode*)malloc(sizeof(ArcNode));
p->nextarc=G->vertices[i].firstarc;
G->vertices[i].firstarc=p;
p->adjvex=j;
q=(ArcNode*)malloc(sizeof(ArcNode));
q->nextarc=G->vertices[j].firstarc;
G->vertices[j].firstarc=q;
q->adjvex=i;
}
}
标签:邻接,建立,scanf,vertices,v2,v1,算法,ArcNode,firstarc
From: https://blog.51cto.com/heliotopekxy/6307395