我是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 |
        +---+   +---+

10-07 19:02
查看更多