pub fn find_trail(mut self, graph: &G) -> Result<Vec<usize>> {
        // If graph has only one vertex, that single vertex is an Eulerian trail.
        if self.out_deg.len() <= 1 {
            return Ok(self.trail);
        }

        let trail_start_id = self.start_of_eulerian_trail();
        let circuit_start_id = self.start_of_eulerian_circuit();

        // If there is no suitable id to start the search from, graph does not have Eulerian trail.
        if trail_start_id.is_none() {
            Err(Error::new_etnf())?
        }

        // Make sure graph has at least one edge to traverse.
        if !self.unused_edges.is_empty() {
            self.rec_execute(graph, trail_start_id.unwrap());
        }

        // Trail actually has the visited vertices in the backward order. So first visited vertex is the last item in the `trail` structure.
        // So for trail to make sense to the user, reverse it before returning it so that first visited vertex is also the first item in the structure.
        self.trail.reverse();

        // IMPORTANT: Note that recursive algorithm that finds the trail actually finds the circuit if the graph also has Eulerian circuit.
        // So if graph also has an Eulerian circuit, pop the last item in the circuit for it to become a trail. This will convert (v1, v2, v3, v1) to (v1, v2, v3)
        if circuit_start_id.is_some() {
            self.trail.pop();
        }

        Ok(self.trail)
    }
/// Finds the Eulerian trail if there is one.
///
/// # Arguments
/// `graph`: Graph to search the Eulerian trail in it.
///
/// # Returns
/// * `Ok`: Containing list of vector ids that will get visited during the Eulerian trail.
/// * `Err`: If graph does not have Eulerian trail.
Finds the Eulerian trail if there is one.
Finds the Eulerian trail if there is one .
pub fn find_trail(mut self, graph: &G) -> Result<Vec<usize>> {
        // If graph has only one vertex, that single vertex is an Eulerian trail.
        if self.out_deg.len() <= 1 {
            return Ok(self.trail);
        }
        let trail_start_id = self.start_of_eulerian_trail();
        let circuit_start_id = self.start_of_eulerian_circuit();
        // If there is no suitable id to start the search from, graph does not have Eulerian trail.
        if trail_start_id.is_none() {
            Err(Error::new_etnf())?
        }
        // Make sure graph has at least one edge to traverse.
        if !self.unused_edges.is_empty() {
            self.rec_execute(graph, trail_start_id.unwrap());
        }
        // Trail actually has the visited vertices in the backward order. So first visited vertex is the last item in the `trail` structure.
        // So for trail to make sense to the user, reverse it before returning it so that first visited vertex is also the first item in the structure.
        self.trail.reverse();
        // IMPORTANT: Note that recursive algorithm that finds the trail actually finds the circuit if the graph also has Eulerian circuit.
        // So if graph also has an Eulerian circuit, pop the last item in the circuit for it to become a trail. This will convert (v1, v2, v3, v1) to (v1, v2, v3)
        if circuit_start_id.is_some() {
            self.trail.pop();
        }
        Ok(self.trail)
    }
pub fn find_trail ( mut self , graph : & G ) -> Result < Vec < usize > > { // If graph has only one vertex, that single vertex is an Eulerian trail. if self . out_deg . len ( ) <= 1 { return Ok ( self . trail ) ; } let trail_start_id = self . start_of_eulerian_trail ( ) ; let circuit_start_id = self . start_of_eulerian_circuit ( ) ; // If there is no suitable id to start the search from, graph does not have Eulerian trail. if trail_start_id . is_none ( ) { Err ( Error :: new_etnf ( ) ) ? } // Make sure graph has at least one edge to traverse. if ! self . unused_edges . is_empty ( ) { self . rec_execute ( graph , trail_start_id . unwrap ( ) ) ; } // Trail actually has the visited vertices in the backward order. So first visited vertex is the last item in the `trail` structure. // So for trail to make sense to the user, reverse it before returning it so that first visited vertex is also the first item in the structure. self . trail . reverse ( ) ; // IMPORTANT: Note that recursive algorithm that finds the trail actually finds the circuit if the graph also has Eulerian circuit. // So if graph also has an Eulerian circuit, pop the last item in the circuit for it to become a trail. This will convert (v1, v2, v3, v1) to (v1, v2, v3) if circuit_start_id . is_some ( ) { self . trail . pop ( ) ; } Ok ( self . trail ) }
Finds the Eulerian trail if there is one.
Finds the Eulerian trail if there is one .
mut self
graph
&G
`Ok`: Containing list of vector ids that will get visited during the Eulerian trail.
`Err`: If graph does not have Eulerian trail.
` Ok ` : Containing list of vector ids that will get visited during the Eulerian trail . ` Err ` : If graph does not have Eulerian trail .
mut self
graph
&G