无向图的邻接矩阵存储

#include 
#include 
#define MAXSIZE 100

typedef struct
{
    char vertex[MAXSIZE];
    int edges[MAXSIZE][MAXSIZE];
} MyGraph;
void GrarhPrint(MyGraph*g,int n);
void CreateMGraph(MyGraph*g,int e,int n);
void CreateMGraph(MyGraph*g,int e,int n)
{
    int i,j,k;
    printf("Input data of vertex(0~n-1):\n");
    for(i=0; i<=n; i++)
    {
        g->vertex[i]=i;
    }
    for(i=1; i<=n; i++)
    {
        for(j=1; j<=n; j++)
        {
            g->edges[i][j]=0;
        }
    }
    for(k=1;k<=e;k++)
    {
        printf("Input edge of(i,j):");
        scanf("%d%d",&i,&j);
        g->edges[i][j]=1;
        g->edges[j][i]=1;
    }
    GrarhPrint(g,n);
}
void GrarhPrint(MyGraph*g,int n)
{
    int i=0;
    int j=0;
    for(i=1;i<=n;i++)
    {
        for(j=1;j<=n;j++)
            printf("%d\t",g->edges[i][j]);//这里输入的是哪两个点之间有路径
        printf("\n");
    }
}
int main()
{
    MyGraph *g=(MyGraph*)malloc(sizeof(MyGraph));
    CreateMGraph(g,4,4);
    return 0;
}

你可能感兴趣的:(计算机知识,数据结构,无向图的邻接矩阵存储)