Implementation and Analysis of Graphs
An adjacency-list representation of a graph primarily consists of a linked list of
adjacency-list structures. Each structure in the list contains two
members: a vertex and a list of vertices adjacent to the vertex. In
the implementation presented here, an individual adjacency list is
represented by the structure AdjList (see
Example 11.1). As you would expect, this structure has two members
that correspond to those just mentioned. Each adjacency list is
implemented as a set (see Chapter
7) for reasons discussed in the questions and answers at the
end of the chapter. The structure Graph
is the graph data structure (see Example 11.1). This structure consists of
five members: vcount is the number of
vertices in the graph, ecount
is the number of edges, match and
destroy are members used to encapsulate the
functions passed to graph_init, and
adjlists is the linked list of
adjacency-list structures. Example
11.1 also defines an enumerated type for vertex colors, which
are often used when working with graphs.
/***************************************************************************** * * * -------------------------------- graph.h ------------------------------- * * * *****************************************************************************/ #ifndef GRAPH_H #define GRAPH_H #include <stdlib.h> #include "list.h" #include "set.h" /***************************************************************************** ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access