#include"sequence.h" #include<stdlib.h> typedef struct { SequenceList Vertices; int edge[10000][10000]; int numOfEdges; }MatrixGraph; void Initiate(MatrixGraph *G,int n)//初始化 { int i,j; for(i=0;i<n;i++) for(j=0;j<n;j++) { if(i==j) G->edge[i][j]=0; else G->edge[i][j]=10000; } G->numOfEdges=0; ListInitialize(&G->Vertices); } void InsertVertex(MatrixGraph *G,ElemType vertex)//插入顶点 { ListInsert(&G->Vertices,G->Vertices.size,vertex); } void InsertEdge(MatrixGraph *G,int v1,int v2,int weight)//插入一条边 { if(v1<0||v1>=G->Vertices.size||v2<0||v2>=G->Vertices.size) { printf("参数v1或v2越界出错!\n"); exit(1); } G->edge[v1][v2]=weight; G->numOfEdges++; }
时间: 2024-03-04 21:54:23 浏览: 23
根据你提供的代码,我看到你定义了一个结构体 `MatrixGraph`,它包含了一个顺序表 `Vertices` 和一个二维数组 `edge`,还有一个整数变量 `numOfEdges`。顺序表 `Vertices` 存储了图中的所有顶点,二维数组 `edge` 存储了图中所有边的权值,整数变量 `numOfEdges` 记录了图中边的数量。
在 `Initiate` 函数中,你使用两个嵌套的循环来初始化了一个空图 `G`。具体地,你将 `edge` 数组中的每个元素初始化为一个比较大的数,表示这两个顶点之间没有边。同时,你将 `numOfEdges` 初始化为 0。
在 `InsertVertex` 函数中,你通过调用顺序表的 `ListInsert` 函数,将新的顶点插入到了顺序表 `Vertices` 的末尾。
在 `InsertEdge` 函数中,你首先检查了参数 `v1` 和 `v2` 是否越界,如果越界则输出错误信息并退出程序。如果没有越界,则将边的权值 `weight` 插入到 `edge` 数组中对应的位置上,并将 `numOfEdges` 加 1。
根据你的问题描述,我猜测你可能是在引用 `MatrixGraph` 结构体变量的时候出现了问题。如果你没有正确地定义或者初始化 `MatrixGraph` 结构体变量,那么在引用它的时候可能会出现问题。
你可以检查一下你的代码,在使用 `MatrixGraph` 结构体变量之前是否有正确地定义和初始化它。另外,你也可以提供更多的细节和上下文,这样我才能更好地回答你的问题。
相关问题
#include <stdio.h> #include <stdlib.h> typedef int ElemType; typedef struct LNode { ElemType da
`#include <stdio.h>`和`#include <stdlib.h>`是C语言中的两个头文件。`<stdio.h>`是标准输入输出头文件,提供了一些用于输入输出的函数和宏定义。`<stdlib.h>`是标准库头文件,提供了一些常用的函数和宏定义,如内存分配、随机数生成等。
在你的代码中,`typedef int ElemType;`定义了一个类型别名,将`int`类型命名为`ElemType`。
`typedef struct LNode`定义了一个结构体类型`LNode`,结构体是一种自定义的数据类型,可以包含多个不同类型的成员变量。在这里,`LNode`结构体中的成员变量还没有完整定义,因此代码截断了。
解释以下头文件:#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h> #include <unistd.h> #include <fcntl.h> #include <pthread.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <ctype.h> #include <sys/pps.h> #include <sys/types.h> #include "camera.h" #include <encoder.h> #include "ppsFunc.h" #include "timeDiff.h"
这些头文件是C语言程序中常用的系统库和自定义头文件。下面对它们进行简要的解释:
- stdio.h:输入输出相关的函数库,如printf、scanf等。
- stdlib.h:标准库函数,包括各种常用函数,如malloc、free等。
- stdint.h:定义了一些整数类型,如int8_t、uint16_t等。
- string.h:提供字符串操作相关的函数,如strcpy、strcat等。
- unistd.h:提供对POSIX操作系统API的访问,如close、read等。
- fcntl.h:提供对文件控制相关的函数,如open、fcntl等。
- pthread.h:多线程相关的函数库,如pthread_create、pthread_join等。
- sys/types.h:提供对系统数据类型的定义,如pid_t、mode_t等。
- sys/socket.h:提供对套接字的操作,如socket、bind等。
- netinet/in.h:提供对TCP/IP网络编程的支持,如struct sockaddr_in等。
- ctype.h:提供对字符分类和转换的函数,如isalpha、isdigit等。
- sys/pps.h:提供对PPS(Pulse-Per-Second)信号的读取和控制。
- camera.h:自定义头文件,可能是和摄像头相关的函数和数据结构。
- encoder.h:自定义头文件,可能是和视频编码相关的函数和数据结构。
- ppsFunc.h:自定义头文件,可能是和PPS信号相关的函数和数据结构。
- timeDiff.h:自定义头文件,可能是和时间差相关的函数和数据结构。
相关推荐
![application/x-gzip](https://img-home.csdnimg.cn/images/20210720083646.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![text/x-c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)