#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define Max 20
typedef char vertextype[Max];
typedef int InfoType;
typedef struct ArcBox
{
int tailvex,headvex;
struct ArcBox *hlink,*tlink;
InfoType info;
}ArcBox;
typedef struct vexnode
{
vertextype data;
ArcBox *firstin,*firstout;
}vexnode;
typedef struct
{
vexnode xlist[Max];
int vexnum,arcnum;
}OLGraph;
OLGraph G;
int LocateVex(OLGraph *H,vertextype c)
{
int i;
for(i=0;i<G.vexnum;i++)
{
if(strcmp(c,H->xlist[i].data))
return i;
}
return 0;
}
main()
{
vertextype a,b;
InfoType intout;
ArcBox *p;
int i,j,k;
printf("please input the number of vertex and arcnode,IncInfo(0 or 1):\n");
scanf("%d%d%d",&G.vexnum,&G.arcnum,&intout);
fflush(stdin);
printf("\n please input the vertex:\n");
for(i=0;i<G.vexnum;i++)
{
scanf("%s",&G.xlist[i].data);
G.xlist[i].firstin=NULL;
G.xlist[i].firstout=NULL;
}
printf("\n please input the arcs:\n");
for(k=0;k<G.arcnum;++k)
{
scanf("%s%s",a,b);
i=LocateVex(&G,a);
j=LocateVex(&G,b);
p=(ArcBox *)malloc(sizeof(ArcBox));
if(!p)
{
printf("overflow!\n");
exit(0);
}
else
{
p->tailvex=i;
p->headvex=j;
G.xlist[j].firstin=G.xlist[i].firstout=p;
if(intout)
{
printf("please input the information:\n");
scanf("%d",p->info);
}
}
}
}
正文
十字链表创建图2005-05-25 13:49:00
【评论】 【打印】 【字体:大 中 小】 本文链接:http://blog.pfan.cn/jay0518/1279.html
阅读(5158) | 评论(0)
版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!
评论