MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / _swap_nodes

Method _swap_nodes

graphs/minimum_spanning_tree_prims2.py:175–184  ·  view source on GitHub ↗
(self, node1_pos: int, node2_pos: int)

Source from the content-addressed store, hash-verified

173 return None
174
175 def _swap_nodes(self, node1_pos: int, node2_pos: int) -> None:
176 # Swap the nodes at the given positions
177 node1_elem = self.heap[node1_pos][0]
178 node2_elem = self.heap[node2_pos][0]
179 self.heap[node1_pos], self.heap[node2_pos] = (
180 self.heap[node2_pos],
181 self.heap[node1_pos],
182 )
183 self.position_map[node1_elem] = node2_pos
184 self.position_map[node2_elem] = node1_pos
185
186
187class GraphUndirectedWeighted[T]:

Callers 3

extract_minMethod · 0.95
_bubble_upMethod · 0.95
_bubble_downMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected