我是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;`
Run Code Online (Sandbox Code Playgroud)
我在这里阅读了几篇相关的帖子,比如" typedef struct vs struct definitions ",但我仍然对这种用法感到困惑:
typedef struct {.... }VNode,AdjList[MAX_VERTEX_NUM];
Run Code Online (Sandbox Code Playgroud)
什么是AdjList?这是一个阵列?如果是这样,这句话意味着什么:
AdjList vertices;
Run Code Online (Sandbox Code Playgroud)
谢谢.参考:http://zh.wikipedia.org/wiki/%E9%82%BB%E6%8E%A5%E8%A1%A8
AdjList
是一个在数组中MAX_VERTEX_NUM
定义的类型的数组struct
.
C中的宣言有点搞笑.
typedef struct {...} AdjList[MAX_VERTEX_NUM]
Run Code Online (Sandbox Code Playgroud)
应该被读作AdjList
定义为MAX_VERTEX_NUM
结构中定义的类型大小的数组.这是一种类型,这意味着您可以将变量声明为此类型的实例.
归档时间: |
|
查看次数: |
82 次 |
最近记录: |