复习(数据结构):图:c语言:邻接矩阵

    xiaoxiao2025-03-21  20

    #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; typedef char VertexType; //顶点类型由用户定义 typedef int EdgeType; // 边上的权值 typedef struct{ VertexType vers[MAXVEX]; EdgeType arc[MAXVEX][MAXVEX]; // 边表 int numNodes,numEdges; //图中的当前顶点和边数 }MGraph; //建立无向图的临接矩阵 void CreateMGraph(MGraph *G){ int i,j,k,w; printf("输入顶点数和边数: "); scanf("%d,%d",&G->numNodes,&G->numEdges); for(i=0,i<G->numNodes;i++) for(j=0;j<G->numNodes;j++) G->arc[i][j]=INFINITY; //邻接矩阵初始化 for(k=0;k<G->numEdges;k++){ printf("输入: "); scanf("%d,%d,%d", &i,&j,&w); G->arc[i][j]=w; G->arc[j][i]=G->arc[i][j]; } } int main(void) { MGraph G; CreateMGraph(&G); return 0; }
    转载请注明原文地址: https://ju.6miu.com/read-1297247.html
    最新回复(0)