MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / topo

Function topo

graphs/basic_graphs.py:189–209  ·  view source on GitHub ↗
(g, ind=None, q=None)

Source from the content-addressed store, hash-verified

187
188
189def topo(g, ind=None, q=None):
190 if q is None:
191 q = [1]
192 if ind is None:
193 ind = [0] * (len(g) + 1) # SInce oth Index is ignored
194 for u in g:
195 for v in g[u]:
196 ind[v] += 1
197 q = deque()
198 for i in g:
199 if ind[i] == 0:
200 q.append(i)
201 if len(q) == 0:
202 return
203 v = q.popleft()
204 print(v)
205 for w in g[v]:
206 ind[w] -= 1
207 if ind[w] == 0:
208 q.append(w)
209 topo(g, ind, q)
210
211
212"""

Callers

nothing calls this directly

Calls 2

popleftMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected