pub fn dfs_iterative<G, F>(graph: &G, start: NodeId, visitor: &mut F)Expand description
Runs an iterative depth-first search from start using an explicit
Stack, calling visitor the first time each node is discovered.
Safe from stack overflow on arbitrarily deep graphs. Note that visit order may differ slightly from the recursive variant because the stack reverses the neighbour ordering.
ยงExamples
use graph_core::{AdjacencyList, Graph};
use graph_traversal::dfs_iterative;
let mut g: AdjacencyList<()> = AdjacencyList::directed();
let a = g.add_node(());
let b = g.add_node(());
let c = g.add_node(());
g.add_edge(a, b, 1.0).unwrap();
g.add_edge(a, c, 1.0).unwrap();
let mut visited = Vec::new();
dfs_iterative(&g, a, &mut |id| visited.push(id));
assert_eq!(visited.len(), 3);
assert!(visited.contains(&a));
assert!(visited.contains(&b));
assert!(visited.contains(&c));