From 5b97ad15ad782977a9b2b1c61356c5aee7fe80e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Claudio=20Cesar=20de=20S=C3=A1?= Date: Fri, 1 Jul 2022 15:37:00 -0300 Subject: [PATCH] examples: add new graph algorithms, make some minor corrections to the programs in examples/graphs (#14562) --- examples/graphs/bellman-ford.v | 4 +--- examples/graphs/dijkstra.v | 2 -- examples/graphs/minimal_spann_tree_prim.v | 14 ++++---------- 3 files changed, 5 insertions(+), 15 deletions(-) diff --git a/examples/graphs/bellman-ford.v b/examples/graphs/bellman-ford.v index 637d50be89..5b1c9c5b95 100644 --- a/examples/graphs/bellman-ford.v +++ b/examples/graphs/bellman-ford.v @@ -8,7 +8,7 @@ https://www.geeksforgeeks.org/bellman-ford-algorithm-dp-23/ For Portugese reference http://rascunhointeligente.blogspot.com/2010/10/o-algoritmo-de-bellman-ford-um.html -By CCS +code by CCS */ const large = 999999 // almost inifinity @@ -159,5 +159,3 @@ fn main() { } println('\n BYE -- OK') } - -//================================================= diff --git a/examples/graphs/dijkstra.v b/examples/graphs/dijkstra.v index 2c945f9ac5..147b022e30 100644 --- a/examples/graphs/dijkstra.v +++ b/examples/graphs/dijkstra.v @@ -237,5 +237,3 @@ fn main() { println('\n BYE -- OK') } - -//******************************************************************** diff --git a/examples/graphs/minimal_spann_tree_prim.v b/examples/graphs/minimal_spann_tree_prim.v index 280b599f88..51809e1683 100644 --- a/examples/graphs/minimal_spann_tree_prim.v +++ b/examples/graphs/minimal_spann_tree_prim.v @@ -7,9 +7,10 @@ by CCS PS: all the pre-requisites of Dijkstra are considered -$ v run file_name.v +$ v run file_name.v + Creating a executable -$ v run file_name.v -o an_executable.EXE +$ v -o an_executable.EXE run file_name.v $ ./an_executable.EXE Code based from : Data Structures and Algorithms Made Easy: Data Structures and Algorithmic Puzzles, Fifth Edition (English Edition) @@ -45,9 +46,7 @@ fn push_pq(mut prior_queue []T, data int, priority int) { temp << prior_queue[i] i++ } - prior_queue = temp.clone() - // I am not sure if it the right way - // IS IT THE RIGHT WAY? + prior_queue = temp.clone() // I am not sure if it the right way } // Change the priority of a value/node ... exist a value, change its priority @@ -193,9 +192,6 @@ fn main() { | / \ | (3)-------(4) 9 - */ - - /* Let us create following weighted graph From https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-algorithm-greedy-algo-2/?ref=lbp 10 @@ -226,5 +222,3 @@ fn main() { } println('\n BYE -- OK') } - -//********************************************************************