From 5a5812c0c7d88c1de2af6f619b660aea9020a08d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Rybn=C3=AD=C4=8Dek?= <59537589+Dzejkobik007@users.noreply.github.com> Date: Fri, 19 Jan 2024 00:00:22 +0100 Subject: [PATCH] Create dijkstra.py --- dev-prg/Dijkstra/dijkstra.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 dev-prg/Dijkstra/dijkstra.py diff --git a/dev-prg/Dijkstra/dijkstra.py b/dev-prg/Dijkstra/dijkstra.py new file mode 100644 index 0000000..bc16ce1 --- /dev/null +++ b/dev-prg/Dijkstra/dijkstra.py @@ -0,0 +1,24 @@ +# Pokus byl... +graph = [ + [0,0,0,1,0], + [4,0,0,0,0], + [2,5,0,0,0], + [3,0,1,0,1], + [6,3,2,9,0] +] +while True: + i = 0 + print("-------") + lastBiggestVal = 0 + lastBiggestNode = -1 + for j in range(0, 5): + if i == j or graph[i][j] < 1: + continue + if lastBiggestVal < graph[i][j]: + lastBiggestVal = graph[i][j] + lastBiggestNode = j + print("Source: {}, Destination: {}, Value: {}".format(i, j, graph[i][j])) + if lastBiggestNode < 0: + break + i = lastBiggestNode + print("Continue to Destination: {} with Value: {}".format(lastBiggestNode, lastBiggestVal))