From b16b08b06a19e1d525fd26a7b695c868c595fa17 Mon Sep 17 00:00:00 2001 From: Xu Bai <1373953675@qq.com> Date: Fri, 2 Aug 2019 23:41:29 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _05.图/01邻接矩阵创建_CreateMGraph.c | 51 ++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 _05.图/01邻接矩阵创建_CreateMGraph.c diff --git a/_05.图/01邻接矩阵创建_CreateMGraph.c b/_05.图/01邻接矩阵创建_CreateMGraph.c new file mode 100644 index 0000000..f187661 --- /dev/null +++ b/_05.图/01邻接矩阵创建_CreateMGraph.c @@ -0,0 +1,51 @@ +#include "stdio.h" +#include "stdlib.h" +#include "io.h" +#include "math.h" +#include "time.h" + +#define OK 1 +#define ERROR 0 +#define TRUE 1 +#define FALSE 0 +#define MAXVEX 100 /* ×î´ó¶¥µãÊý£¬Ó¦ÓÉÓû§¶¨Òå */ +#define INFINITY 65535 + +typedef int Status; /* StatusÊǺ¯ÊýµÄÀàÐÍ,ÆäÖµÊǺ¯Êý½á¹û״̬´úÂ룬ÈçOKµÈ */ +typedef char VertexType; /* ¶¥µãÀàÐÍÓ¦ÓÉÓû§¶¨Òå */ +typedef int EdgeType; /* ±ßÉϵÄȨֵÀàÐÍÓ¦ÓÉÓû§¶¨Òå */ +typedef struct +{ + VertexType vexs[MAXVEX]; /* ¶¥µã±í */ + EdgeType arc[MAXVEX][MAXVEX];/* ÁÚ½Ó¾ØÕ󣬿ɿ´×÷±ß±í */ + int numNodes, numEdges; /* ͼÖе±Ç°µÄ¶¥µãÊýºÍ±ßÊý */ +}MGraph; + +/* ½¨Á¢ÎÞÏòÍøÍ¼µÄÁÚ½Ó¾ØÕó±íʾ */ +void CreateMGraph(MGraph *G) +{ + int i,j,k,w; + printf("ÊäÈë¶¥µãÊýºÍ±ßÊý:\n"); + scanf("%d,%d",&G->numNodes,&G->numEdges); /* ÊäÈë¶¥µãÊýºÍ±ßÊý */ + for(i = 0;i numNodes;i++) /* ¶ÁÈë¶¥µãÐÅÏ¢,½¨Á¢¶¥µã±í */ + scanf(&G->vexs[i]); + for(i = 0;i numNodes;i++) + for(j = 0;j numNodes;j++) + G->arc[i][j]=INFINITY; /* ÁÚ½Ó¾ØÕó³õʼ»¯ */ + for(k = 0;k numEdges;k++) /* ¶ÁÈënumEdgesÌõ±ß£¬½¨Á¢ÁÚ½Ó¾ØÕó */ + { + printf("ÊäÈë±ß(vi,vj)ÉϵÄϱêi£¬Ï±êjºÍȨw:\n"); + scanf("%d,%d,%d",&i,&j,&w); /* ÊäÈë±ß(vi,vj)ÉϵÄȨw */ + G->arc[i][j]=w; + G->arc[j][i]= G->arc[i][j]; /* ÒòΪÊÇÎÞÏòͼ£¬¾ØÕó¶Ô³Æ */ + } +} + +int main(void) +{ + MGraph G; + CreateMGraph(&G); + + return 0; +} +