aboutsummaryrefslogtreecommitdiffstats
path: root/src/graph.c
diff options
context:
space:
mode:
authorMaksymilian Jopek <maks@jopek.eu>2023-03-26 15:53:00 +0200
committerMaksymilian Jopek <maks@jopek.eu>2023-03-26 17:37:35 +0200
commit5a2665c21b511ef90967af053f6a1d504b78afff (patch)
tree12b6727b0f1742132063eed1927b98c81f7352b1 /src/graph.c
downloadcstructures-5a2665c21b511ef90967af053f6a1d504b78afff.tar.gz
cstructures-5a2665c21b511ef90967af053f6a1d504b78afff.tar.zst
cstructures-5a2665c21b511ef90967af053f6a1d504b78afff.zip
Stack, queue and graph data structures implemented in C using linked lists.
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;
+}
+