From 5a2665c21b511ef90967af053f6a1d504b78afff Mon Sep 17 00:00:00 2001 From: Maksymilian Jopek Date: Sun, 26 Mar 2023 15:53:00 +0200 Subject: Stack, queue and graph data structures implemented in C using linked lists. --- src/main.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main.c (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..07e629b --- /dev/null +++ b/src/main.c @@ -0,0 +1,55 @@ +#include "graph.h" +#include "queue.h" +#include "stack.h" +#include +#include + +#define GRAPH_SIZE 5 + +int main() { + Queue *queue = queueAlloc(); + queueAdd(queue, 1); + queueAdd(queue, 2); + queueAdd(queue, 3); + queueAdd(queue, 4); + queueAdd(queue, 5); + queueAdd(queue, 6); + printf("%d\n", queuePop(queue)); + printf("%d\n", queuePop(queue)); + printf("%d\n", queuePop(queue)); + printf("%d\n", queuePop(queue)); + printf("%d\n", queuePop(queue)); + printf("%d\n", queuePop(queue)); + queueFree(queue); + Stack *stack = stackAlloc(); + stackAdd(stack, 1); + stackAdd(stack, 2); + stackAdd(stack, 3); + stackAdd(stack, 4); + stackAdd(stack, 5); + stackAdd(stack, 6); + printf("%d\n", stackPop(stack)); + printf("%d\n", stackPop(stack)); + printf("%d\n", stackPop(stack)); + printf("%d\n", stackPop(stack)); + printf("%d\n", stackPop(stack)); + printf("%d\n", stackPop(stack)); + stackFree(stack); + + struct vertexList *graph = vertexAlloc(GRAPH_SIZE); + vertexAdd(graph, 0, 1); + vertexAdd(graph, 1, 2); + vertexAdd(graph, 1, 0); + vertexAdd(graph, 2, 3); + vertexAdd(graph, 3, 4); + vertexAdd(graph, 1, 4); + + for (int j = 0; j < GRAPH_SIZE; j++) { + printf("%d:", j); + for (struct vertex *i = graph[j].first; i != NULL; i = i->next) { + printf(" %ld,", i->number); + } + printf("\n"); + } +} + -- cgit v1.3.1