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

时间:2015-03-14 02:28:32

标签: algorithm graph

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

邻接列表表示简单:

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
}

我的问题是如何将顶点与边缘链接?

1 个答案:

答案 0 :(得分:1)

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