mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-03-30 02:16:43 +00:00
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
This commit is contained in:
parent
da0717b9ae
commit
18319a8733
@ -2,6 +2,7 @@ from collections import deque
|
|||||||
import heapq
|
import heapq
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
|
||||||
# First implementation of johnson algorithm
|
# First implementation of johnson algorithm
|
||||||
class JohnsonGraph:
|
class JohnsonGraph:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -52,7 +53,6 @@ class JohnsonGraph:
|
|||||||
# perform the johnson algorithm to handle the negative weights that could not be handled by either the dijkstra
|
# perform the johnson algorithm to handle the negative weights that could not be handled by either the dijkstra
|
||||||
# or the bellman ford algorithm efficiently
|
# or the bellman ford algorithm efficiently
|
||||||
def johnson_algo(self):
|
def johnson_algo(self):
|
||||||
|
|
||||||
self.add_vertices("#")
|
self.add_vertices("#")
|
||||||
for v in self.graph:
|
for v in self.graph:
|
||||||
if v != "#":
|
if v != "#":
|
||||||
@ -79,6 +79,7 @@ class JohnsonGraph:
|
|||||||
distances.append(new_dist)
|
distances.append(new_dist)
|
||||||
return distances
|
return distances
|
||||||
|
|
||||||
|
|
||||||
g = JohnsonGraph()
|
g = JohnsonGraph()
|
||||||
# this a complete connected graph
|
# this a complete connected graph
|
||||||
g.add_vertices("A")
|
g.add_vertices("A")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user