File tree Expand file tree Collapse file tree 1 file changed +17
-0
lines changed
Expand file tree Collapse file tree 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)
3636 return graph ;
3737}
3838
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+
3954// A structure to represent a subset for union-find
4055struct subset
4156{
@@ -131,6 +146,7 @@ void KruskalMST(struct Graph *graph)
131146 }
132147 // Else discard the next_edge
133148 }
149+ free (subsets );
134150
135151 // print the contents of result[] to display the
136152 // built MST
@@ -182,6 +198,7 @@ int main()
182198 graph -> edge [4 ].weight = 4 ;
183199
184200 KruskalMST (graph );
201+ deleteGraph (graph );
185202
186203 return 0 ;
187204}
You can’t perform that action at this time.
0 commit comments