正文

十字链表创建图2005-05-25 13:49:00

【评论】 【打印】 【字体: 】 本文链接:http://blog.pfan.cn/jay0518/1279.html

分享到:

#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);    } } } } 

阅读(5274) | 评论(0)


版权声明:编程爱好者网站为此博客服务提供商,如本文牵涉到版权问题,编程爱好者网站不承担相关责任,如有版权问题请直接与本文作者联系解决。谢谢!

评论

暂无评论
您需要登录后才能评论,请 登录 或者 注册