十年网站开发经验 + 多家企业客户 + 靠谱的建站团队
量身定制 + 运营维护+专业推广+无忧售后,网站问题一站解决
#include#include #include typedef char VertexType[5]; //存储顶点值 #define MaxSize 50 #define INIT 10000 typedef struct //邻接矩阵,存储弧的信息 { int adj; }ArcNode,AdjMatrix[MaxSize][MaxSize]; typedef struct //图的类型定义 { VertexType vex[MaxSize]; //存储顶点值 AdjMatrix arc; //邻接矩阵 int arcnum,vexnum; //前者弧数,后者顶点数 }MGraph; void CreateVertex(MGraph *G) //创建邻接矩阵 { int i,j,k,w; VertexType v1,v2; printf("请输入有向带权图的顶点数和弧数:(空格间隔)\n"); scanf("%d%d",&(*G).vexnum,&(*G).arcnum); printf("请输入%d个顶点的值:\n",G->vexnum); for ( i=0 ; i vexnum ; i++ ) { scanf("%s",&G->vex[i]); } for ( i=0 ; i vexnum ; i++ ) //初始化邻接矩阵 { for ( j=0 ; j vexnum ; j++ ) { G->arc[i][j].adj = INIT; } } printf("请输入%d条弧的弧尾,弧头和权值:\n",G->arcnum); for ( k=0 ; k arcnum ; k++ ) { scanf("%s%s%d",v1,v2,&w); i = LocateVertex(*G,v1); j = LocateVertex(*G,v2); G->arc[i][j].adj = w; } } int LocateVertex(MGraph G,VertexType v) //索引 { int i; for ( i=0 ; i
文章题目:邻接矩阵表示有向带权图
标题网址:http://shouzuofang.com/article/pgshoj.html