fn next(&mut self) -> Option<Self::Item> {
        //Sources:
        // https://www.geeksforgeeks.org/iterative-depth-first-traversal/
        // https://en.wikipedia.org/wiki/Depth-first_search
        while let Some(&s) = self.stack.last() {

            //Does s still have neighbors we need to process?
            if let Some((_,s_nbr)) = self.adj_iters[s].next() {
                if !self.visited[s_nbr] {
                    self.stack.push(s_nbr);
                }
            } else {
                //s has no more neighbors, we can pop it off the stack
                self.stack.pop();
            }

            // Stack may contain same vertex twice. So
            // we return the popped item only
            // if it is not visited.
            if !self.visited[s] {
                self.visited.set(s, true);
                return Some(s);
            }
        }

        None
    }
/// Returns next vertex in the DFS
Returns next vertex in the DFS
Returns next vertex in the DFS
fn next(&mut self) -> Option<Self::Item> {
        //Sources:
        // https://www.geeksforgeeks.org/iterative-depth-first-traversal/
        // https://en.wikipedia.org/wiki/Depth-first_search
        while let Some(&s) = self.stack.last() {
            //Does s still have neighbors we need to process?
            if let Some((_,s_nbr)) = self.adj_iters[s].next() {
                if !self.visited[s_nbr] {
                    self.stack.push(s_nbr);
                }
            } else {
                //s has no more neighbors, we can pop it off the stack
                self.stack.pop();
            }
            // Stack may contain same vertex twice. So
            // we return the popped item only
            // if it is not visited.
            if !self.visited[s] {
                self.visited.set(s, true);
                return Some(s);
            }
        }
        None
    }
fn next ( & mut self ) -> Option < Self :: Item > { //Sources: // https://www.geeksforgeeks.org/iterative-depth-first-traversal/ // https://en.wikipedia.org/wiki/Depth-first_search while let Some ( & s ) = self . stack . last ( ) { //Does s still have neighbors we need to process? if let Some ( ( _ , s_nbr ) ) = self . adj_iters [ s ] . next ( ) { if ! self . visited [ s_nbr ] { self . stack . push ( s_nbr ) ; } } else { //s has no more neighbors, we can pop it off the stack self . stack . pop ( ) ; } // Stack may contain same vertex twice. So // we return the popped item only // if it is not visited. if ! self . visited [ s ] { self . visited . set ( s , true ) ; return Some ( s ) ; } } None }
Returns next vertex in the DFS
Returns next vertex in the DFS
&mut self
&mut self