From debe9d400758d28933346de0464212239ff1ac65 Mon Sep 17 00:00:00 2001 From: Johhannas Reyn <127910206+JohhannasReyn@users.noreply.github.com> Date: Tue, 1 Oct 2024 04:01:23 -0700 Subject: [PATCH] Update floyd_warshall.cpp Fix Segmentation fault do to graph being passed by object and there not being a copy constructor. Adding the '&' for the Graph parameter changes the passing of the parameter to pass by reference, thus avoiding the segmentation fault. --- dynamic_programming/floyd_warshall.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/floyd_warshall.cpp b/dynamic_programming/floyd_warshall.cpp index d193ebbd589..02a682f07a5 100644 --- a/dynamic_programming/floyd_warshall.cpp +++ b/dynamic_programming/floyd_warshall.cpp @@ -51,7 +51,7 @@ void print(int dist[], int V) { // The main function that finds the shortest path from a vertex // to all other vertices using Floyd-Warshall Algorithm. -void FloydWarshall(Graph graph) { +void FloydWarshall(Graph& graph) { int V = graph.vertexNum; int dist[V][V];