pub fn compute_dfs_tree(&self, start_index: usize) -> Result<Graph<NullVertex, NullEdge>> {
        if !self.has_vertex(start_index) {
            bail!("vertex does not exist");
        }

        let mut tree = Graph::new();
        let mut stack = Vec::new();

        tree.insert_vertex(NullVertex::new(start_index))?;
        for &successor in &self.successors[&start_index] {
            stack.push((start_index, successor));
        }

        while let Some((pred, index)) = stack.pop() {
            if tree.has_vertex(index) {
                continue;
            }

            tree.insert_vertex(NullVertex::new(index))?;
            tree.insert_edge(NullEdge::new(pred, index))?;

            for &successor in &self.successors[&index] {
                stack.push((index, successor));
            }
        }

        Ok(tree)
    }
/// Creates a DFS tree with NullVertex and NullEdge
Creates a DFS tree with NullVertex and NullEdge
Creates a DFS tree with NullVertex and NullEdge
pub fn compute_dfs_tree(&self, start_index: usize) -> Result<Graph<NullVertex, NullEdge>> {
        if !self.has_vertex(start_index) {
            bail!("vertex does not exist");
        }
        let mut tree = Graph::new();
        let mut stack = Vec::new();
        tree.insert_vertex(NullVertex::new(start_index))?;
        for &successor in &self.successors[&start_index] {
            stack.push((start_index, successor));
        }
        while let Some((pred, index)) = stack.pop() {
            if tree.has_vertex(index) {
                continue;
            }
            tree.insert_vertex(NullVertex::new(index))?;
            tree.insert_edge(NullEdge::new(pred, index))?;
            for &successor in &self.successors[&index] {
                stack.push((index, successor));
            }
        }
        Ok(tree)
    }
pub fn compute_dfs_tree ( & self , start_index : usize ) -> Result < Graph < NullVertex , NullEdge > > { if ! self . has_vertex ( start_index ) { bail ! ( " " ) ; } let mut tree = Graph :: new ( ) ; let mut stack = Vec :: new ( ) ; tree . insert_vertex ( NullVertex :: new ( start_index ) ) ? ; for & successor in & self . successors [ & start_index ] { stack . push ( ( start_index , successor ) ) ; } while let Some ( ( pred , index ) ) = stack . pop ( ) { if tree . has_vertex ( index ) { continue ; } tree . insert_vertex ( NullVertex :: new ( index ) ) ? ; tree . insert_edge ( NullEdge :: new ( pred , index ) ) ? ; for & successor in & self . successors [ & index ] { stack . push ( ( index , successor ) ) ; } } Ok ( tree ) }
Creates a DFS tree with NullVertex and NullEdge
Creates a DFS tree with NullVertex and NullEdge
&self
start_index
usize
&self
start_index
usize