addtition: graph create
This commit is contained in:
18
src/graph.c
18
src/graph.c
@@ -2,6 +2,7 @@
|
||||
#include "arraylist.h"
|
||||
#include <inttypes.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
struct Vertex {
|
||||
ArrayList *edges;
|
||||
@@ -16,3 +17,20 @@ struct Graph {
|
||||
ArrayList *vertices;
|
||||
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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user