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

Method print_graph

graphs/breadth_first_search.py:14–24  ·  view source on GitHub ↗

prints adjacency list representation of graaph >>> g = Graph() >>> g.print_graph() >>> g.add_edge(0, 1) >>> g.print_graph() 0 : 1

(self)

Source from the content-addressed store, hash-verified

12 self.vertices: dict[int, list[int]] = {}
13
14 def print_graph(self) -> None:
15 """
16 prints adjacency list representation of graaph
17 >>> g = Graph()
18 >>> g.print_graph()
19 >>> g.add_edge(0, 1)
20 >>> g.print_graph()
21 0 : 1
22 """
23 for i in self.vertices:
24 print(i, " : ", " -> ".join([str(j) for j in self.vertices[i]]))
25
26 def add_edge(self, from_vertex: int, to_vertex: int) -> None:
27 """

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected