MCPcopy Index your code
hub / github.com/subbarayudu-j/TheAlgorithms-Python / add_edge

Method add_edge

Graphs/dijkstra_algorithm.py:88–101  ·  view source on GitHub ↗
(self, u, v, w)

Source from the content-addressed store, hash-verified

86 self.par = [-1] * self.num_nodes # To store the path
87
88 def add_edge(self, u, v, w):
89 # Edge going from node u to v and v to u with weight w
90 # u (w)-> v, v (w) -> u
91 # Check if u already in graph
92 if u in self.adjList.keys():
93 self.adjList[u].append((v, w))
94 else:
95 self.adjList[u] = [(v, w)]
96
97 # Assuming undirected graph
98 if v in self.adjList.keys():
99 self.adjList[v].append((u, w))
100 else:
101 self.adjList[v] = [(u, w)]
102
103 def show_graph(self):
104 # u -> v(w)

Callers 1

Calls 1

keysMethod · 0.80

Tested by

no test coverage detected