addtition: graph veretx count and get veretx

This commit is contained in:
2026-05-06 20:47:08 -06:00
parent 36fa8aa09b
commit 60b9830db7
2 changed files with 25 additions and 1 deletions

View File

@@ -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

View File

@@ -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;
}