Skip to content

Commit 4db1f40

Browse files
fix: vla in floyd_warshall
1 parent f7154b7 commit 4db1f40

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

dynamic_programming/floyd_warshall.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ class Graph {
2525
}
2626

2727
~Graph() {
28-
for (int i = 0; i < vertexNum; i++) delete[] edges[i];
28+
for (int i = 0; i < vertexNum; i++) {
29+
delete[] edges[i];
30+
}
2931
delete[] edges;
3032
}
3133

@@ -36,7 +38,7 @@ class Graph {
3638
};
3739

3840
// Utility function to print distances
39-
void print(int dist[], int V) {
41+
void print(const std::vector<int> dist, int V) {
4042
cout << "\nThe Distance matrix for Floyd - Warshall" << endl;
4143
for (int i = 0; i < V; i++) {
4244
for (int j = 0; j < V; j++) {
@@ -77,7 +79,7 @@ void FloydWarshall(Graph graph) {
7779
dist[i][j] = dist[i][k] + dist[k][j];
7880

7981
// Convert 2d array to 1d array for print
80-
int dist1d[V * V];
82+
std::vector<int> dist1d(V * V);
8183
for (int i = 0; i < V; i++)
8284
for (int j = 0; j < V; j++) dist1d[i * V + j] = dist[i][j];
8385

0 commit comments

Comments
 (0)