]>
wirehaze git hosting - graph-theory.git/blob - graph/bfs.c
2 #include "graph/search.h"
7 bfs_ (struct graph
*g
, struct graph
*bt
, struct state
*vs
, unsigned int ri
)
11 struct state
*rs
, *ns
;
16 if (!(sq
.q
= calloc (g
->nv
, sizeof *sq
.q
)))
26 ri
= vertex_id (g
, r
);
30 while (e
&& (n
= e
->to
))
32 ni
= vertex_id (g
, n
);
39 if ((err
= add_arc (bt
, ri
, ni
)))
66 if (!(bt
= new_graph (g
->nv
)))
69 if (!(vs
= calloc (g
->nv
, sizeof *vs
)))
72 for (vi
= 0; vi
< g
->nv
; ++vi
)
73 if (vs
[vi
].c
== WHITE
)
74 if (bfs_ (g
, bt
, vs
, vi
))