diff --git a/ADV_2 - Dijkstra's Algorithm.py b/ADV_2 - Dijkstra's Algorithm.py index e6f3c28..b28c634 100644 --- a/ADV_2 - Dijkstra's Algorithm.py +++ b/ADV_2 - Dijkstra's Algorithm.py @@ -74,17 +74,23 @@ class Graph(): uNode = self.unpoppedQ[u] #v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v v - - prevNode = 1 - for value in edges: - for value in edges: - nodeWeight = int(value[2]) - print(nodeWeight) - temp = nodeWeight - if temp < (nodeWeight + prevNode): - print(prevNode) - nodeWeight = temp - prevNode = value + +## '''Dijkstra's Algorithm +## input: Nodes and weights +## output: Shortest path between two nodes +## Implements Dijkstra's shortest path algorithm +## ''' + + for value in edges: #loops through all edges + prevNode = value[0] #sets first node as source node + nodeWeight = int(value[2]) #sets the weight of the node + temp = nodeWeight #creates temporary value using weight of the node + print("node weight: ", nodeWeight) #prints result for the user + print("previous node: ", prevNode) + print() + if temp < (nodeWeight + prevNode): #if the weight is less than the previous weight + nodeWeight = temp #set the weight as the new lower weight + prevNode = value #^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^