addition: destroy graph
This commit is contained in:
18
src/graph.c
18
src/graph.c
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user