addition: destroy graph

This commit is contained in:
2026-05-06 20:20:45 -06:00
parent 8b6ec8ce2e
commit d75adf8510
2 changed files with 21 additions and 2 deletions

View File

@@ -34,3 +34,21 @@ Graph *graph_create(GraphType type) {
return graph;
}
GraphErr graph_destroy(Graph **graph) {
if (graph == NULL || *graph) {
return GRAPH_NULL_ARG;
}
size_t vertex_count = arraylist_size((*graph)->vertices);
for (size_t i = 0; i < vertex_count; i++) {
Vertex vertex;
arraylist_get((*graph)->vertices, i, &vertex);
arraylist_destroy(&vertex.edges);
}
arraylist_destroy(&(*graph)->vertices);
return GRAPH_OK;
}