MCPcopy Index your code
hub / github.com/TheAlgorithms/Go / hasCycleHelper

Method hasCycleHelper

graph/cycle.go:30–47  ·  view source on GitHub ↗
(v int, all, visiting, visited map[int]struct{})

Source from the content-addressed store, hash-verified

28}
29
30func (g Graph) hasCycleHelper(v int, all, visiting, visited map[int]struct{}) bool {
31 delete(all, v)
32 visiting[v] = struct{}{}
33
34 neighbors := g.edges[v]
35 for v := range neighbors {
36 if _, ok := visited[v]; ok {
37 continue
38 } else if _, ok := visiting[v]; ok {
39 return true
40 } else if g.hasCycleHelper(v, all, visiting, visited) {
41 return true
42 }
43 }
44 delete(visiting, v)
45 visited[v] = struct{}{}
46 return false
47}
48
49// this function can do HasCycle() job but it is slower
50func (g *Graph) FindAllCycles() []Graph {

Callers 1

HasCycleMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected