Skip to content

Commit

Permalink
Added solution for detecting cycles.
Browse files Browse the repository at this point in the history
  • Loading branch information
root-11 committed Feb 27, 2024
1 parent 87e8129 commit 65ab8b5
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion graph/cycle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .base import BasicGraph
from .topological_sort import topological_sort


def cycle(graph, start, mid, end=None):
Expand Down Expand Up @@ -39,7 +40,7 @@ def has_cycles(graph):
if n1 == n2: # detect nodes that point to themselves
return True
try:
_ = list(graph.phase_lines()) # tries to create a DAG.
_ = list(topological_sort(graph)) # tries to create a DAG.
return False
except AttributeError:
return True

0 comments on commit 65ab8b5

Please sign in to comment.