weixin_66658457 2022-07-19 22:27
浏览 18
已结题

邻接表到输入两顶点的时后直接就退出了

代码运行不到输入两个顶点的时候就结束了
#include<stdio.h>

#include<stdlib.h>
#define MAX_SIZE 100
typedef char MapType;
typedef struct EdgeNode
{
int adjvex;
MapType info;
struct EdgeNode* next;
}EdgeNode;
typedef struct MapHat
{
MapType data;
struct EdgeNode* firstchild;
}AdjList[MAX_SIZE], MapHat;
typedef struct
{
AdjList adjList;
int numEdge, numNodes;
}GraphAdjList;
void CreatALGraph(GraphAdjList* G);
void CreatALGraph(GraphAdjList* G)
{
printf("请输入边数和端点数\n");
scanf("%d %d", &(G->numEdge), &(G->numNodes));
printf("请输入端点\n");
for (int i = 0; i < G->numNodes; i++)
{
scanf("%c ", &((G->adjList[i]).data));
G->adjList[i].firstchild = NULL;
}
EdgeNode* e;
printf("请输入有连线两点\n");
for (int k = 0; k < G->numEdge; k++)
{
int h, j;
scanf("%d %d", &h, &j);
e = (EdgeNode*)malloc(sizeof(EdgeNode));
e->adjvex = h;
e->next = G->adjList[j].firstchild;
G->adjList[j].firstchild = e;
e = (EdgeNode*)malloc(sizeof(EdgeNode));
e->adjvex = j;
e->next = G->adjList[h].firstchild;
G->adjList[h].firstchild = e;
}
}
int main()
{
GraphAdjList M;
CreatALGraph(&M);
return 0;
}

到请输入有连线两点的时候直接没了
我调试可以进printf("请输入有连线两点\n");下面的for循环,但是输不了数据
  • 写回答

0条回答 默认 最新

    报告相同问题?

    问题事件

    • 系统已结题 7月27日
    • 创建了问题 7月19日

    悬赏问题

    • ¥20 这张图页脚代码该怎么写?
    • ¥20 WPF MVVM模式 handycontrol 框架, hc:SearchBar 控件 Text="{Binding NavMenusKeyWords}" 绑定取不到值
    • ¥15 需要手写数字信号处理Dsp三个简单题 不用太复杂
    • ¥15 数字信号处理考试111
    • ¥15 allegro17.2生成bom表是空白的
    • ¥15 请问一下怎么打通CAN通讯
    • ¥20 如何在 rocky9.4 部署 CDH6.3.2?
    • ¥35 navicat将excel中的数据导入mysql出错
    • ¥15 rt-thread线程切换的问题
    • ¥15 高通uboot 打印ubi init err 22