MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / topo

Function topo

Graphs/basic_graphs.py:142–160  ·  view source on GitHub ↗
(G, ind=None, Q=[1])

Source from the content-addressed store, hash-verified

140
141
142def topo(G, ind=None, Q=[1]):
143 if ind is None:
144 ind = [0] * (len(G) + 1) # SInce oth Index is ignored
145 for u in G:
146 for v in G[u]:
147 ind[v] += 1
148 Q = deque()
149 for i in G:
150 if ind[i] == 0:
151 Q.append(i)
152 if len(Q) == 0:
153 return
154 v = Q.popleft()
155 print(v)
156 for w in G[v]:
157 ind[w] -= 1
158 if ind[w] == 0:
159 Q.append(w)
160 topo(G, ind, Q)
161
162
163"""

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected