Skip to main content

bfs

Function bfs 

Source
pub fn bfs(graph: &Graph, root: VertexId) -> IgraphResult<Vec<VertexId>>
Expand description

Visit order of vertices reachable from root, in BFS order.

Vertices unreachable from root are not included. Errors if root is not a valid vertex.

ยงExamples

use rust_igraph::{Graph, bfs};

// 0 - 1 - 3
// |
// 2
let mut g = Graph::with_vertices(4);
g.add_edge(0, 1).unwrap();
g.add_edge(0, 2).unwrap();
g.add_edge(1, 3).unwrap();

let order = bfs(&g, 0).unwrap();
assert_eq!(order, vec![0, 1, 2, 3]);