addtition: graph veretx count and get veretx
This commit is contained in:
@@ -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
|
||||
|
||||
24
src/graph.c
24
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user