每个顶点都有一个值的图形表示

Graph representation with a value in each vertex

我知道如何用邻接表表示来表示图,我也知道矩阵表示(参考:算法设计手册)

邻接表表示很简单:

struct edge {
    int y;
    int weight;
    struct edge *next;
};

struct graph {
    int n;
    struct edge *edges[N];
}

但现在我想把值放在顶点,而边没有值

struct vertex {
    int value; // to be used for sums later
    struct vertex *parent;
    struct vertex *child;
}

struct edge {
    struct vertex *start;
    struct vertex *end;
}

struct graph {
    int n;
    struct vertex *v[N]; // array of vertices
    // How do I link the vertices and the edges?
    // struct edge
}

我的问题是如何 link 有边的顶点?

struct graph {
  int n_nodes;
  struct node {
    int value;
    int n_adjacents;
    int *adjacent_indices;
  } **nodes;
} graph;