From 60b9830db7d79cc11a1e5d2e7a619afbc6d704b8 Mon Sep 17 00:00:00 2001 From: laentropia Date: Wed, 6 May 2026 20:47:08 -0600 Subject: [PATCH] addtition: graph veretx count and get veretx --- include/graph.h | 2 +- src/graph.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) 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; +}