欢迎来到天天文库
浏览记录
ID:16342185
大小:40.00 KB
页数:5页
时间:2018-08-09
《分别采用邻接矩阵、邻接表存储结构实现图的遍历》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、#defineINFINITY0#defineINF32767#defineMAX_NUM20#defineMAXV100#includetypedefcharVRType;typedefenum{DG=1,DN,UDG,UDN}GraphKind;typedefstructArcCell{VRTypeadj;ArcCell*info;}AdjMatrix[MAX_NUM][MAX_NUM];typedefstruct{VRTypevexs[MAX_NUM];AdjMatrixarcs;intvexnum,arcnum;GraphKindkind;
2、}MGraph;voidPRIN(MGraph&G);intLocateVex(MGraph&G,VRTypev1);intFirstAdjVex(MGraph&G,intv);intNextAdjVex(MGraph&G,intv,intw);voidCreateUDN(MGraph&G){inti,j,k,w;VRTypev1,v2;G.kind=UDN;printf("构造无向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);get
3、char();for(i=0;i4、",&v2);getchar();printf("w(int):");scanf("%d",&w);getchar();i=LocateVex(G,v1);j=LocateVex(G,v2);G.arcs[i][j].adj=w;G.arcs[j][i].adj=G.arcs[i][j].adj;}}intLocateVex(MGraph&G,VRTypev1){inti;for(i=0;i5、v1,v2;G.kind=DN;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、rcs[i][j].info=NULL;}for(k=0;k7、d=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
4、",&v2);getchar();printf("w(int):");scanf("%d",&w);getchar();i=LocateVex(G,v1);j=LocateVex(G,v2);G.arcs[i][j].adj=w;G.arcs[j][i].adj=G.arcs[i][j].adj;}}intLocateVex(MGraph&G,VRTypev1){inti;for(i=0;i5、v1,v2;G.kind=DN;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、rcs[i][j].info=NULL;}for(k=0;k7、d=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
5、v1,v2;G.kind=DN;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、rcs[i][j].info=NULL;}for(k=0;k7、d=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
6、rcs[i][j].info=NULL;}for(k=0;k7、d=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
7、d=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
此文档下载收益归作者所有