Helper function to fill the stack with vertices in the order of their finish times.
(v int, visited []bool, stack *[]int)
| 48 | |
| 49 | // Helper function to fill the stack with vertices in the order of their finish times. |
| 50 | func (g *Graph) fillOrder(v int, visited []bool, stack *[]int) { |
| 51 | visited[v] = true |
| 52 | |
| 53 | for neighbor := range g.edges[v] { |
| 54 | if !visited[neighbor] { |
| 55 | g.fillOrder(neighbor, visited, stack) |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | // Push the current vertex to the stack after exploring all neighbors. |
| 60 | *stack = append(*stack, v) |
| 61 | } |
| 62 | |
| 63 | // Helper function to create a transposed (reversed) graph. |
| 64 | func (g *Graph) transpose() *Graph { |