这是什么意思:"typedef struct{...} VNode,AdjList[20]"
What does it mean: "typedef struct{...} VNode,AdjList[20]"
我是 C 初学者,正在学习 Graph 的一些数据结构。
今天在维基百科上看了一段C代码:
#define MAX_VERTEX_NUM 20
typedef struct ArcNode
{
int adjvex; /* Position of Arc's Vertex */
struct ArcNode *nextarc; /* Pointer to next Arc */
InfoType *info; /* Weight) */
}ArcNode; /* Node */
typedef struct
{
VertexType data; /* Vertex Information */
ArcNode *firstarc; /* Location to the first list node */
}VNode,AdjList[MAX_VERTEX_NUM]; /* Head Node */
typedef struct
{
AdjList vertices;
int vexnum,arcnum; /* Vertex count and Arc count */
GraphKind kind; /* type of Garph, directed, undirected..*/
}ALGraph;`
我在这里读了几个相关的post,比如“typedef struct vs struct definitions”,但我对这个用法还是有点困惑:
typedef struct {.... }VNode,AdjList[MAX_VERTEX_NUM];
那么什么是 AdjList?它是一个数组?如果是这样,这个语句是什么意思:
AdjList vertices;
谢谢。
参考:http://zh.wikipedia.org/wiki/%E9%82%BB%E6%8E%A5%E8%A1%A8
AdjList
是 struct
.
中定义的类型的大小为 MAX_VERTEX_NUM
的数组
C 中的声明有点滑稽。
typedef struct {...} AdjList[MAX_VERTEX_NUM]
应理解为 AdjList
被定义为结构中定义的类型的大小为 MAX_VERTEX_NUM
的数组。这是一个类型,这意味着您可以将变量声明为该类型的实例。
AdjList
是类型 "array of the type defined in the struct
",大小为 MAX_VERTEX_NUM
。
一个更简单的例子来演示正在发生的事情:
typedef int myintarray[10];
int main()
{
myintarray array; // same as "int array[10]"
array[2] = 2 ;
}
我是 C 初学者,正在学习 Graph 的一些数据结构。 今天在维基百科上看了一段C代码:
#define MAX_VERTEX_NUM 20
typedef struct ArcNode
{
int adjvex; /* Position of Arc's Vertex */
struct ArcNode *nextarc; /* Pointer to next Arc */
InfoType *info; /* Weight) */
}ArcNode; /* Node */
typedef struct
{
VertexType data; /* Vertex Information */
ArcNode *firstarc; /* Location to the first list node */
}VNode,AdjList[MAX_VERTEX_NUM]; /* Head Node */
typedef struct
{
AdjList vertices;
int vexnum,arcnum; /* Vertex count and Arc count */
GraphKind kind; /* type of Garph, directed, undirected..*/
}ALGraph;`
我在这里读了几个相关的post,比如“typedef struct vs struct definitions”,但我对这个用法还是有点困惑:
typedef struct {.... }VNode,AdjList[MAX_VERTEX_NUM];
那么什么是 AdjList?它是一个数组?如果是这样,这个语句是什么意思:
AdjList vertices;
谢谢。 参考:http://zh.wikipedia.org/wiki/%E9%82%BB%E6%8E%A5%E8%A1%A8
AdjList
是 struct
.
MAX_VERTEX_NUM
的数组
C 中的声明有点滑稽。
typedef struct {...} AdjList[MAX_VERTEX_NUM]
应理解为 AdjList
被定义为结构中定义的类型的大小为 MAX_VERTEX_NUM
的数组。这是一个类型,这意味着您可以将变量声明为该类型的实例。
AdjList
是类型 "array of the type defined in the struct
",大小为 MAX_VERTEX_NUM
。
一个更简单的例子来演示正在发生的事情:
typedef int myintarray[10];
int main()
{
myintarray array; // same as "int array[10]"
array[2] = 2 ;
}