diff options
| author | Maksymilian Jopek <maks@jopek.eu> | 2023-03-26 15:53:00 +0200 |
|---|---|---|
| committer | Maksymilian Jopek <maks@jopek.eu> | 2023-03-26 17:37:35 +0200 |
| commit | 5a2665c21b511ef90967af053f6a1d504b78afff (patch) | |
| tree | 12b6727b0f1742132063eed1927b98c81f7352b1 /src/main.c | |
| download | cstructures-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/main.c')
| -rw-r--r-- | src/main.c | 55 |
1 files changed, 55 insertions, 0 deletions
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 <stdio.h> +#include <stdlib.h> + +#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"); + } +} + |
