pub fn compute_post_order(&self, root: usize) -> Result<Vec<usize>> {
        let mut visited: FxHashSet<usize> = FxHashSet::default();
        let mut order: Vec<usize> = Vec::new();

        fn dfs_walk<V: Vertex, E: Edge>(
            graph: &Graph<V, E>,
            node: usize,
            visited: &mut FxHashSet<usize>,
            order: &mut Vec<usize>,
        ) -> Result<()> {
            visited.insert(node);
            for successor in &graph.successors[&node] {
                if !visited.contains(successor) {
                    dfs_walk(graph, *successor, visited, order)?;
                }
            }
            order.push(node);
            Ok(())
        }

        dfs_walk(self, root, &mut visited, &mut order)?;

        Ok(order)
    }
// Compute the post order of all vertices in the graph
Compute the post order of all vertices in the graph
Compute the post order of all vertices in the graph
pub fn compute_post_order(&self, root: usize) -> Result<Vec<usize>> {
        let mut visited: FxHashSet<usize> = FxHashSet::default();
        let mut order: Vec<usize> = Vec::new();
        fn dfs_walk<V: Vertex, E: Edge>(
            graph: &Graph<V, E>,
            node: usize,
            visited: &mut FxHashSet<usize>,
            order: &mut Vec<usize>,
        ) -> Result<()> {
            visited.insert(node);
            for successor in &graph.successors[&node] {
                if !visited.contains(successor) {
                    dfs_walk(graph, *successor, visited, order)?;
                }
            }
            order.push(node);
            Ok(())
        }
        dfs_walk(self, root, &mut visited, &mut order)?;
        Ok(order)
    }
pub fn compute_post_order ( & self , root : usize ) -> Result < Vec < usize > > { let mut visited : FxHashSet < usize > = FxHashSet :: default ( ) ; let mut order : Vec < usize > = Vec :: new ( ) ; fn dfs_walk < V : Vertex , E : Edge > ( graph : & Graph < V , E > , node : usize , visited : & mut FxHashSet < usize > , order : & mut Vec < usize > , ) -> Result < ( ) > { visited . insert ( node ) ; for successor in & graph . successors [ & node ] { if ! visited . contains ( successor ) { dfs_walk ( graph , * successor , visited , order ) ? ; } } order . push ( node ) ; Ok ( ( ) ) } dfs_walk ( self , root , & mut visited , & mut order ) ? ; Ok ( order ) }
Compute the post order of all vertices in the graph
Compute the post order of all vertices in the graph
&self
root
usize
&self
root
usize