迟早要玩 2022-11-12 23:12 采纳率: 0%
浏览 26

求解决,这是什么问题,代码都没错

问题遇到的现象和发生背景
用代码块功能插入代码,请勿粘贴截图
我想要达到的结果
#include<stdio.h>
#include<malloc.h>
#define INF 32767
#define MAXV 100
typedef char InfoType;
typedef struct
{    int no;
    InfoType info;
}VertexType;
typedef struct
{    int edges[MAXV][MAXV];
    int n,e;
    VertexType vexs[MAXV];
}MatGraph;
typedef struct ANode
{    int adjvex;
    struct ANode * nextarc;
    int weight;
}ArcNode;
typedef struct Vnode
{    InfoType info;
    int count;
    ArcNode * firstarc;
}VNode;
typedef struct
{    VNode adjlist[MAXV];
    int n,e;
}AdjGraph;
void CreateMat(MatGraph &g,int A[MAXV][MAXV],int n,int e)
{    int i,j;
    g.n=n,g.e=e;
    for(i=0;i<g.n;j++)
        for(j=0;j<g.n;j++)
            g.edges[i][j]=A[i][j];
}
void DispMat(MatGraph g)
{    int i,j;
    for(i=0;i<g.n;i++)
    {    for(j=0;j<g.n;j++)
            if(g.edges[i][j]!=INF)
                printf("%4d",g.edges[i][j]);
            else
                printf("%4s","∞");
        printf("\n");
    }
}
void CreateAdj(AdjGraph * &G,int A[MAXV][MAXV],int n,int e)
{    int i,j;
    ArcNode * p;
    G=(AdjGraph *)malloc(sizeof(AdjGraph));
    for(i=0;i<n;i++)
        G->adjlist[i].firstarc=NULL;
    for(i=0;i<n;i++)
        for(j=n-1;j>=0;j--)
            if(A[i][j]!=0&&A[i][j]!=INF)
            {    p=(ArcNode *)malloc(sizeof(ArcNode));
                p->adjvex=j;
                p->weight=A[i][j];
                p->nextarc=G->adjlist[i].firstarc;
                G->adjlist[i].firstarc=p;
            }
    G->n=n; G->e=n; 
}
void DispAdj(AdjGraph * G)
{    ArcNode *p;
    for(int i=0;i<G->n;i++)
    {    p=G->adjlist[i].firstarc;
        printf("%3d:",i);
        while(p!=NULL)
        {    printf("%3d[%d]→",p->adjvex,p->weight);
            p=p->nextarc;
        }
        printf("^\n");
     } 
}
void DestroyAdj(AdjGraph * &G)
{    ArcNode *pre,*p;
    for(int i=0;i<G->n;i++)
    {    pre=G->adjlist[i].firstarc;
        if(pre!=NULL)
        {    p=pre->nextarc;
            while(p!=NULL)
            {    free(pre);
                pre=p; p=p->nextarc;
            }
            free(pre);
        }
    }
    free(G);
}
```c
#include"graph.cpp"
int main()
{    
    MatGraph g;
    AdjGraph *G;
    int A[MAXV][MAXV]={
    {0,5,INF,7,INF,INF},{INF,0,4,INF,INF,INF},
    {8,INF,0,INF,INF,9},{INF,INF,5,0,INF,6},
    {INF,INF,INF,5,0,INF},{3,INF,INF,INF,1,0}};
    int n=6,e=10;
    printf("(1)图G的邻接矩阵:\n");
    CreateMat(g,A,n,e);
    printf("(1)图G的邻接矩阵:\n");DispMat(g);
    printf("(2)图G的邻接表:\n");
    DestroyAdj(G);
    return 1;
}

![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/104538562866174.png "#left")

![img](https://img-mid.csdnimg.cn/release/static/image/mid/ask/233058562866116.png "#left")
  • 写回答

1条回答 默认 最新

  • SoftwareTeacher 《编程之美》作者 2022-11-13 00:13
    关注

    请问你想解决什么问题?

    评论

报告相同问题?

问题事件

  • 创建了问题 11月12日

悬赏问题

  • ¥15 编辑cmake lists 明明写了project项目名,但是还是报错怎么回事
  • ¥15 关于#计算机视觉#的问题:求一份高质量桥梁多病害数据集
  • ¥15 特定网页无法访问,已排除网页问题
  • ¥50 如何将脑的图像投影到颅骨上
  • ¥15 提问一个关于vscode相关的环境配置问题,就是输入中文但是显示不出来,代码在idea可以显示中文,但在vscode不行,不知道怎么配置环境
  • ¥15 netcore使用PuppeteerSharp截图
  • ¥20 这张图页头,页脚具体代码该怎么写?
  • ¥15 关于#sql#的问题,请各位专家解答!
  • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
  • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂