大橙子网站建设,新征程启航
为企业提供网站建设、域名注册、服务器等服务
#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://dzwzjz.com/article/pgshoj.html