From 0ceb3b340e93d4db11b2107e1264583884aec23f Mon Sep 17 00:00:00 2001 From: Idan BananI Date: Tue, 11 Jan 2022 20:20:32 +0200 Subject: [PATCH] Update dijkstra.c (#928) in this way valgrind checks will pass and result will stay the same (functions as a static variable) --- data_structures/graphs/dijkstra.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data_structures/graphs/dijkstra.c b/data_structures/graphs/dijkstra.c index b1faa472..f15de530 100644 --- a/data_structures/graphs/dijkstra.c +++ b/data_structures/graphs/dijkstra.c @@ -32,7 +32,8 @@ void addEdge(struct Graph *G, int src, int dst, int weight) // Utility function to find minimum distance vertex in mdist int minDistance(int mdist[], int vset[], int V) { - int minVal = INT_MAX, minInd; + int minVal = INT_MAX; + static int minInd = -1; //remembers the previous value if not modified in the loop for (int i = 0; i < V; i++) if (vset[i] == 0 && mdist[i] < minVal) {