図の隣接行列表示-C言語

1077 ワード

図の隣接マトリックス表示

#include 
#include 

//#define INT_MAX 0XFFFFFF
#define INFINIFY INT_MAX
#define MAX_VERTEX_NUM 100

typedef struct Graph
{
    int vexs[MAX_VERTEX_NUM+1];
    int AdjMatrix[MAX_VERTEX_NUM+1][MAX_VERTEX_NUM+1];
    int vexnum, edgenum;
}Graph;

void CreatGraph(Graph &g)
{
    int i,j;
    printf("Please input vertex and edges number: ");
    scanf("%d %d", &g.vexnum, &g.edgenum);
    for(i=0; ib and its weight: ");
        scanf("%d %d %d", &a, &b, &w);
        g.AdjMatrix[a][b] = g.AdjMatrix[b][a] = w;
    }
}

void PrintGraph(Graph g)
{
    int i, j;
    for(i=0; i