[prev] 129 [next]

Weighted Graph Representation (cont)

Sample adjacency matrix implementation in C requires minimal changes to previous Graph ADT:

WGraph.h

// edges are pairs of vertices (end-points) plus positive weight
typedef struct Edge {
   Vertex v;
   Vertex w;
   int    weight;
} Edge;

// returns weight, or 0 if vertices not adjacent
int adjacent(Graph, Vertex, Vertex);