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