Skip to content
Permalink
Browse files
Add files via upload
  • Loading branch information
flemingt2 committed Apr 19, 2022
1 parent 9c5439b commit 92ffab7f1c0b7a6e8b7df2d2fe1b03e542d44209
Showing 1 changed file with 17 additions and 11 deletions.
@@ -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

#^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^

0 comments on commit 92ffab7

Please sign in to comment.