我是C和结构的新手,我有一个我想理解的代码,是否有人可以用图形的方式向我解释这两个结构如何相互关联,就像结构图中的结构节点一样
struct Graph {
// An array of pointers to Node to represent adjacency list
struct Node* head[N];
};
// A data structure to store adjacency list nodes of the graph
struct Node {
int dest;
struct Node* next;
};
最佳答案
Graph
具有一个数组(可能为null)指向Node
的指针。
每个Node
都有一个指向另一个Node
的指针(可能为null)。
一个图可能看起来像这样,例如:
+-----+-----+-...-+-----+-----+
Graph: | | | ... | | |
| | | 0 | ... | 0 | | |
+--|--+-----+-...-+-----+--|--+
| |
| V
| +---+ +---+ +---+
| Node: | ---->| ---->| 0 |
| +---+ +---+ +---+
|
V
+---+ +---+
Node: | ---->| 0 |
+---+ +---+