addtition: graph create

This commit is contained in:
2026-05-06 20:08:36 -06:00
parent 94cfb10960
commit 8b6ec8ce2e

View File

@@ -2,6 +2,7 @@
#include "arraylist.h" #include "arraylist.h"
#include <inttypes.h> #include <inttypes.h>
#include <stdint.h> #include <stdint.h>
#include <stdlib.h>
struct Vertex { struct Vertex {
ArrayList *edges; ArrayList *edges;
@@ -16,3 +17,20 @@ struct Graph {
ArrayList *vertices; ArrayList *vertices;
GraphType type; GraphType type;
}; };
Graph *graph_create(GraphType type) {
Graph *graph = malloc(sizeof(Graph));
if (graph == NULL) {
return NULL;
}
graph->type = type;
graph->vertices = arraylist_init(64, sizeof(Vertex));
if (graph->vertices == NULL) {
free(graph);
return NULL;
}
return graph;
}