mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-02-20 08:12:02 +00:00
trying to fix build error - 1
This commit is contained in:
parent
fdbf9b12e5
commit
70c4dabf8d
|
@ -185,6 +185,11 @@ class DirectedGraph:
|
|||
>>> g.add_pair(2, 3)
|
||||
>>> g.topological_sort()
|
||||
[1, 2, 3]
|
||||
>>> g.add_pair(3, 1) # Introducing a cycle
|
||||
>>> g.topological_sort()
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Graph has cycles, cannot perform topological sort.
|
||||
"""
|
||||
stack = []
|
||||
visited = []
|
||||
|
@ -223,6 +228,9 @@ class DirectedGraph:
|
|||
>>> g.add_pair(2, 1)
|
||||
>>> g.cycle_nodes()
|
||||
[1, 2]
|
||||
>>> g.add_pair(2, 3)
|
||||
>>> g.cycle_nodes() # No cycles now
|
||||
[]
|
||||
"""
|
||||
stack = []
|
||||
visited = []
|
||||
|
@ -277,6 +285,12 @@ class DirectedGraph:
|
|||
>>> g.add_pair(2, 1)
|
||||
>>> g.has_cycle()
|
||||
True
|
||||
>>> g.add_pair(2, 3)
|
||||
>>> g.has_cycle()
|
||||
True # Still has a cycle
|
||||
>>> g.remove_pair(1, 2) # Now no cycle
|
||||
>>> g.has_cycle()
|
||||
False
|
||||
"""
|
||||
stack = []
|
||||
visited = []
|
||||
|
|
Loading…
Reference in New Issue
Block a user