欢迎来到天天文库
浏览记录
ID:15645726
大小:40.00 KB
页数:5页
时间:2018-08-04
《分别采用邻接矩阵、邻接表存储结构实现图的遍历》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
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;}MGraph;v
2、oidPRIN(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);getchar();for(i=0;i3、.vexnum;i++){printf("G.vexs[%d]:",i);sscanf("%c",&G.vexs[i]);getchar();}for(i=0;i4、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、intf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、printf("v1(char):");scanf("%c",&v1);getchar();printf("v2(char):");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;}}voidCreateDG(MGraph&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",7、&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
3、.vexnum;i++){printf("G.vexs[%d]:",i);sscanf("%c",&G.vexs[i]);getchar();}for(i=0;i4、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、intf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、printf("v1(char):");scanf("%c",&v1);getchar();printf("v2(char):");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;}}voidCreateDG(MGraph&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",7、&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
4、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、intf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、printf("v1(char):");scanf("%c",&v1);getchar();printf("v2(char):");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;}}voidCreateDG(MGraph&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",7、&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
5、intf("G.vexnum:");scanf("%d",&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i6、printf("v1(char):");scanf("%c",&v1);getchar();printf("v2(char):");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;}}voidCreateDG(MGraph&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",7、&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
6、printf("v1(char):");scanf("%c",&v1);getchar();printf("v2(char):");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;}}voidCreateDG(MGraph&G){inti,j,k;VRTypev1,v2;G.kind=DG;printf("构造有向网");printf("G.vexnum:");scanf("%d",
7、&G.vexnum);printf("G.arcnum:");scanf("%d",&G.arcnum);getchar();for(i=0;i
此文档下载收益归作者所有