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

#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,inumNodes;i++)
        for(j=0;jnumNodes;j++)
            G->arc[i][j]=INFINITY;  //邻接矩阵初始化
    for(k=0;knumEdges;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;
}

你可能感兴趣的:(复习(数据结构:c语言))