欢迎来到天天文库
浏览记录
ID:11149565
大小:40.00 KB
页数:5页
时间:2018-07-10
《分别采用邻接矩阵、邻接表存储结构实现图的遍历》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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;GraphKind
2、kind;}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.a
3、rcnum);getchar();for(i=0;i4、r):");scanf("%c",&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、G){inti,j,k,w;VRTypev1,v2;G.kind=DN;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、cs[i][j].adj=INFINITY;G.arcs[i][j].info=NULL;}for(k=0;k7、&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i8、s[i][j].adj=INFINITY;G.arcs[i][j]
4、r):");scanf("%c",&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、G){inti,j,k,w;VRTypev1,v2;G.kind=DN;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、cs[i][j].adj=INFINITY;G.arcs[i][j].info=NULL;}for(k=0;k7、&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i8、s[i][j].adj=INFINITY;G.arcs[i][j]
5、G){inti,j,k,w;VRTypev1,v2;G.kind=DN;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、cs[i][j].adj=INFINITY;G.arcs[i][j].info=NULL;}for(k=0;k7、&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i8、s[i][j].adj=INFINITY;G.arcs[i][j]
6、cs[i][j].adj=INFINITY;G.arcs[i][j].info=NULL;}for(k=0;k7、&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i8、s[i][j].adj=INFINITY;G.arcs[i][j]
7、&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i8、s[i][j].adj=INFINITY;G.arcs[i][j]
8、s[i][j].adj=INFINITY;G.arcs[i][j]
此文档下载收益归作者所有