Skip to content

Commit 0501a37

Browse files
authored
Merge pull request #11 from IUCompilerCourse/apt-graph
fixes to graph.py
2 parents 196b352 + f73a50d commit 0501a37

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

graph.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ def __hash__(self):
2020
def __eq__(self, other):
2121
return self.raw() == other.raw()
2222

23+
Vertex = any
24+
2325
################################################################################
2426
# Directed Adjacency List
2527
################################################################################
@@ -181,7 +183,7 @@ def show(self):
181183
# Topological Sort
182184
################################################################################
183185

184-
def topological_sort(G: DirectedAdjList) -> DirectedAdjList:
186+
def topological_sort(G: DirectedAdjList) -> [Vertex]:
185187
in_degree = {u: 0 for u in G.vertices()}
186188
for e in G.edges():
187189
in_degree[e.target] += 1
@@ -201,6 +203,8 @@ def topological_sort(G: DirectedAdjList) -> DirectedAdjList:
201203

202204
def transpose(G: DirectedAdjList) -> DirectedAdjList:
203205
G_t = DirectedAdjList()
206+
for v in G.vertices():
207+
G_t.add_vertex(v)
204208
for e in G.edges():
205209
G_t.add_edge(e.target, e.source)
206210
return G_t

0 commit comments

Comments
 (0)