File tree 1 file changed +17
-0
lines changed 1 file changed +17
-0
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,21 @@ struct Graph *createGraph(int V, int E)
36
36
return graph ;
37
37
}
38
38
39
+ /**
40
+ * @brief Deallocates memory associated with a given graph.
41
+ *
42
+ * @param ptr Pointer to the graph structure to be deallocated.
43
+ */
44
+ void deleteGraph (struct Graph * graph )
45
+ {
46
+ if (graph == NULL )
47
+ {
48
+ return ;
49
+ }
50
+ free (graph -> edge );
51
+ free (graph );
52
+ }
53
+
39
54
// A structure to represent a subset for union-find
40
55
struct subset
41
56
{
@@ -131,6 +146,7 @@ void KruskalMST(struct Graph *graph)
131
146
}
132
147
// Else discard the next_edge
133
148
}
149
+ free (subsets );
134
150
135
151
// print the contents of result[] to display the
136
152
// built MST
@@ -182,6 +198,7 @@ int main()
182
198
graph -> edge [4 ].weight = 4 ;
183
199
184
200
KruskalMST (graph );
201
+ deleteGraph (graph );
185
202
186
203
return 0 ;
187
204
}
You can’t perform that action at this time.
0 commit comments