graph.c (459B)
1 #include "graph.h" 2 3 void graph_init(graph_t *g, const size_t n) { 4 g->n = n; 5 g->nbrs = malloc(n * sizeof(*(g->nbrs))); 6 7 size_t i; 8 for (i = 0; i < n; i++) 9 stack_u64_init(&g->nbrs[i]); 10 } 11 12 void graph_clear(graph_t *g) { 13 size_t i; 14 for (i = 0; i < g->n; i++) 15 stack_u64_clear(&g->nbrs[i]); 16 free(g->nbrs); 17 } 18 19 void graph_add_edge(graph_t *g, const size_t v, const size_t w) { 20 stack_u64_push(&g->nbrs[v], w); 21 stack_u64_push(&g->nbrs[w], v); 22 }