aboutsummaryrefslogtreecommitdiffstats
path: root/src/graph.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/graph.c')
-rw-r--r--src/graph.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/graph.c b/src/graph.c
new file mode 100644
index 0000000..f7c4b1d
--- /dev/null
+++ b/src/graph.c
@@ -0,0 +1,27 @@
+#include <stdlib.h>
+#include "graph.h"
+
+struct vertexList *vertexAlloc(size_t length) {
+ struct vertexList *vertices = malloc(sizeof(*vertices) * length);
+ for(size_t i = 0; i < length; i++) {
+ vertices[i].first = NULL;
+ vertices[i].last = NULL;
+ }
+ return vertices;
+}
+
+void vertexAdd(
+ struct vertexList *list, size_t toWhich, size_t whichOne
+) {
+ struct vertex *new = malloc(sizeof(*new));
+ new->number = whichOne;
+ new->next = NULL;
+ if(list[toWhich].first == NULL) {
+ list[toWhich].first = new;
+ list[toWhich].last = new;
+ return;
+ }
+ list[toWhich].last->next = new;
+ list[toWhich].last = new;
+}
+