File size: 814 Bytes
bff4ec7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "sll_def.h"

/*
 * Recursive depth-first search over a linked-list adjacency graph.
 *
 * Vertices are numbered from 0 through vertex_count - 1.  For every vertex
 * u, adjacency[u] is the head of a linked list whose data fields contain u's
 * neighbor vertex numbers.  The graph storage is read-only; visited is
 * supplied by the caller and is updated in place.
 */
void dfs_adjacency_list(struct list **adjacency, int vertex_count,
                        int *visited, int vertex)
{
    visited[vertex] = 1;
    struct list *edge = adjacency[vertex];
    while (edge != (struct list *)0) {
        int neighbor = edge->data;
        if (visited[neighbor] == 0) {
            dfs_adjacency_list(adjacency, vertex_count, visited, neighbor);
        } else {
        }
        edge = edge->next;
    }
}