addition: destroy graph
This commit is contained in:
@@ -10,7 +10,8 @@ typedef struct Edge Edge;
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
GRAPH_OK,
|
GRAPH_OK,
|
||||||
GRAPH_BAD_ALLOC,
|
GRAPH_BAD_ALLOC,
|
||||||
GRAPH_NOT_FOUND,
|
GRAPH_VERTEX_NOT_FOUND,
|
||||||
|
GRAPH_NULL_ARG,
|
||||||
} GraphErr ;
|
} GraphErr ;
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
@@ -19,7 +20,7 @@ typedef enum {
|
|||||||
} GraphType;
|
} GraphType;
|
||||||
|
|
||||||
Graph *graph_create(GraphType type);
|
Graph *graph_create(GraphType type);
|
||||||
GraphErr graph_destroy(Graph *graph);
|
GraphErr graph_destroy(Graph **graph);
|
||||||
|
|
||||||
GraphErr graph_add_vertex(Graph *graph);
|
GraphErr graph_add_vertex(Graph *graph);
|
||||||
|
|
||||||
|
|||||||
18
src/graph.c
18
src/graph.c
@@ -34,3 +34,21 @@ Graph *graph_create(GraphType type) {
|
|||||||
|
|
||||||
return graph;
|
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