图及其应用实验六Word格式文档下载.docx
- 文档编号:20212887
- 上传时间:2023-01-19
- 格式:DOCX
- 页数:13
- 大小:39.63KB
图及其应用实验六Word格式文档下载.docx
《图及其应用实验六Word格式文档下载.docx》由会员分享,可在线阅读,更多相关《图及其应用实验六Word格式文档下载.docx(13页珍藏版)》请在冰豆网上搜索。
typedefstructVertexTypevexsMAX_VERTEX_NUM;
/顶点向量intarcsMAX_VERTEX_NUMMAX_VERTEX_NUM;
/邻接矩阵intvexnum,arcnum;
/顶点数和弧的数目GraphKindkind;
/图的种类MGraph;
intLovateVex(MGraphG,VertexTypev);
StatusCreateUDN(MGraph&
G);
StatusCreateDN(MGraph&
StatusCreateUDG(MGraph&
StatusCreateDG(MGraph&
StatusCreateGraph(MGraph&
voidPrintGraph(MGraphG);
voidGraphDegree(MGraphG);
主函数:
#include1.hintmain()MGraphG;
CreateGraph(G);
/创建图PrintGraph(G);
/输出图GraphDegree(G);
/计算图中顶点的度,并输出printf(“n”);
return0;
功能函数:
intLovateVex(MGraphG,VertexTypev)for(inti=0;
G.vexsi!
=v;
i+);
returni;
G)inti,j,k;
VertexTypev1,v2;
intw;
printf(输入图的顶点数和边数:
n);
scanf(“%d%d”,&
G.vexnum,&
G.arcnum);
printf(输入图的顶点信息:
for(i=0;
iG.vexnum;
i+)scanf(“%c”,&
G.vexsi);
i+)for(j=0;
jG.vexnum;
j+)G.arcsij=INIFINITY;
printf(输入边的信息v1,v2,wn);
for(k=0;
kG.arcnum;
k+)scanf(“%c%c%c”,&
v1,&
v2,&
w);
i=LovateVex(G,v1);
j=LovateVex(G,v2);
G.arcsij=w;
G.arcsji=G.arcsij;
/forkreturnOK;
j+)G.arcsij=0;
printf(输入边的信息v1,v2n);
k+)scanf(“%c%c”,&
v2);
G.arcsij=1;
iG.vexsi;
G)intkind;
pritnf(输入图的类型:
0-DG,1-DN,2-UDG,3-UDN:
scanf(“%d”,&
kind);
G.kind=(GraphKind)kind;
switch(G.kind)caseDG:
returnCreateDG(G);
caseDN:
returnCreateDN(G);
caseUDG:
returnCreateUDG(G);
caseUDN:
returnCreateUDN(G);
default:
returnERROR;
voidPrintGraph(MGraphG)inti,j;
printf(图的顶点数和边数:
%d%dn,G.vexnum,G.arcnum);
printf(图的顶点信息:
i+)printf(“%c”,G.vexsi);
printf(图的邻接矩阵:
i+)printf(“n”);
for(j=0;
j+)if(G.arcsij=INIFINITY)printf();
elseprintf(“%c”,G.arcsij);
/foriprintf(“n”);
voidGraphDegree(MGraphG)intindegreeMAX_VERTEX_NUM=0,outdegreeMAX_VERTEX_NUM=0;
inti;
switch(G.kind)caseDN:
caseDG:
FindIndegree(G,indegree);
i+)printf(“%c的出度为%dn”,G.vexsi,outdegreei);
FindOutdegree(G,outdegree);
break;
i+)printf(“%c的度为%dn”,G.vexsi,outdegreei);
printf(“n”);
运行结果:
程序代码部分:
/1.h#include#include#defineOK1#defineERROR0#defineTRUE1#defineFALSE0#defineOVERFLOW-1typedefintStatus;
typedefintInfoType;
typedefstructArcNodeintadjvex;
InfoTypeweight;
structArcNode*nextarc;
ArcNode;
typedefstructVnodeVertexTypedata;
ArcNode*firstarc;
VNode,AdjListMAX_VERTEX_NUM;
typedefstructAdjListvertices;
intvexnum,arcnum;
GraphKindkind;
ALGraph;
intLovateVex(ALGraphG,VertexTypev)StatusCreateUDN(ALGraph&
G)StatusCreateGraph(ALGraph&
G)voidPrintGraph(ALGraphG)主函数:
#include1.hintmain()ALGraphG;
/建立图PrintGraph(G);
/输出图return0;
intLovateVex(ALGraphG,VertexTypev)for(inti=0;
G.verticesi.data!
StatusCreateUDN(ALGraph&
InfoTypew;
ArcNode*p,*q;
pritnf(输入图的顶点信息:
i+)scanf(“%d”,&
G.verticesi.data);
G.verticesi.firstarc=NULL;
printf(输入边的信息v1,v2,weightn);
kadjvex=j;
p-weight=w;
p-nextarc=G.verticesi.firstarc;
G.verticesi.firstarc=p;
q=(ArcNode*)malloc(sizeof(ArcNode);
q-adjvex=i;
q-nextarc=G.verticesj.firstarc;
G.verticesj.firstarc=q;
returnOK;
StatusCreateGraph(ALGraph&
printf(输入图的类型:
switch(G.kind)/caseDG:
/caseUDG:
voidPrintGraph(ALGraphG)inti,j;
ArcNode*p;
printf(图的邻接表:
iadjvex;
printf(“%d”,G.verticesj.data);
p=p-nextarc;
/whileprintf(“n”);
/forprintf(“n”);
四.实验结果的分析与评价(该部分如不够填写,请另加附页)1.图的无向和有向,边数和点数决定了存储图的方式。
注:
实验成绩等级分为(90100分)优,(8089分)良,(70-79分)中,(6069分)及格,(59分)不及格。
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 及其 应用 实验