diff --git a/include/graph.h b/include/graph.h index 844049a..d9ca7ea 100644 --- a/include/graph.h +++ b/include/graph.h @@ -30,7 +30,7 @@ GraphErr graph_connect_vertex( size_t node2, size_t weight); -GraphErr graph_vertex_count(size_t *out); +GraphErr graph_vertex_count(Graph *graph, size_t *out); GraphErr graph_get_vertex(Graph *graph, size_t index, Vertex *out); #endif diff --git a/src/graph.c b/src/graph.c index c7c08df..536485b 100644 --- a/src/graph.c +++ b/src/graph.c @@ -98,3 +98,27 @@ GraphErr graph_connect_vertex( return GRAPH_OK; } + +GraphErr graph_vertex_count(Graph *graph, size_t *out) { + if (graph == NULL) { + return GRAPH_NULL_ARG; + } + + *out = arraylist_size(graph->vertices); + + return GRAPH_OK; +} + +GraphErr graph_get_vertex(Graph *graph, size_t index, Vertex *out) { + if (graph == NULL || out == NULL) { + return GRAPH_NULL_ARG; + } + + if (index >= arraylist_size(graph->vertices)) { + return GRAPH_VERTEX_NOT_FOUND; + } + + arraylist_get(graph->vertices, index, out); + + return GRAPH_OK; +}