pub fn compute_pre_order(&self, root: usize) -> Result<Vec<usize>> {
        if !self.has_vertex(root) {
            bail!("vertex does not exist");
        }

        let mut visited: FxHashSet<usize> = FxHashSet::default();
        let mut stack: Vec<usize> = Vec::new();
        let mut order: Vec<usize> = Vec::new();

        stack.push(root);

        while let Some(node) = stack.pop() {
            if !visited.insert(node) {
                continue;
            }

            order.push(node);

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

        Ok(order)
    }
/// Compute the pre order of all vertices in the graph
Compute the pre order of all vertices in the graph
Compute the pre order of all vertices in the graph
pub fn compute_pre_order(&self, root: usize) -> Result<Vec<usize>> {
        if !self.has_vertex(root) {
            bail!("vertex does not exist");
        }
        let mut visited: FxHashSet<usize> = FxHashSet::default();
        let mut stack: Vec<usize> = Vec::new();
        let mut order: Vec<usize> = Vec::new();
        stack.push(root);
        while let Some(node) = stack.pop() {
            if !visited.insert(node) {
                continue;
            }
            order.push(node);
            for &successor in &self.successors[&node] {
                stack.push(successor);
            }
        }
        Ok(order)
    }
pub fn compute_pre_order ( & self , root : usize ) -> Result < Vec < usize > > { if ! self . has_vertex ( root ) { bail ! ( " " ) ; } let mut visited : FxHashSet < usize > = FxHashSet :: default ( ) ; let mut stack : Vec < usize > = Vec :: new ( ) ; let mut order : Vec < usize > = Vec :: new ( ) ; stack . push ( root ) ; while let Some ( node ) = stack . pop ( ) { if ! visited . insert ( node ) { continue ; } order . push ( node ) ; for & successor in & self . successors [ & node ] { stack . push ( successor ) ; } } Ok ( order ) }
Compute the pre order of all vertices in the graph
Compute the pre order of all vertices in the graph
&self
root
usize
&self
root
usize