From 03b7ee8494f65121b16590b9cd85d928a90b3e72 Mon Sep 17 00:00:00 2001 From: clfreville2 Date: Fri, 14 Oct 2022 09:30:20 +0200 Subject: [PATCH] =?UTF-8?q?Ajoute=20un=20court=20paquet=20de=20listes=20ch?= =?UTF-8?q?a=C3=AEn=C3=A9es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +++ linked-list/Makefile | 16 ++++++++++++++++ linked-list/src/linkedList.c | 18 ++++++++++++++++++ linked-list/src/linkedList.h | 13 +++++++++++++ linked-list/test/testLinkedList.c | 11 +++++++++++ 5 files changed, 61 insertions(+) create mode 100644 linked-list/Makefile create mode 100644 linked-list/src/linkedList.c create mode 100644 linked-list/src/linkedList.h create mode 100644 linked-list/test/testLinkedList.c diff --git a/.gitignore b/.gitignore index 57c3dad..6151ace 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,9 @@ .idea *.swp +# Build +build + # Executables test* !test/ diff --git a/linked-list/Makefile b/linked-list/Makefile new file mode 100644 index 0000000..6d6ed93 --- /dev/null +++ b/linked-list/Makefile @@ -0,0 +1,16 @@ +all: test + +test: testLinkedList + ./testLinkedList + +testLinkedList: build/linkedList.o build/testLinkedList.o + gcc -o $@ $^ + +build/linkedList.o: src/linkedList.c src/linkedList.h | build + gcc -Wall -c src/linkedList.c -o build/linkedList.o + +build/testLinkedList.o: test/testLinkedList.c src/linkedList.h | build + gcc -Wall -Isrc/ -c test/testLinkedList.c -o build/testLinkedList.o + +build: + mkdir build diff --git a/linked-list/src/linkedList.c b/linked-list/src/linkedList.c new file mode 100644 index 0000000..e98e763 --- /dev/null +++ b/linked-list/src/linkedList.c @@ -0,0 +1,18 @@ +#include "linkedList.h" + +#include + +LinkedList createLinkedList(void) { + return NULL; +} + +void freeLinkedList(LinkedList *list) { + struct list_node *next; + struct list_node *node = *list; + while (node != NULL) { + next = node->next; + free(node); + node = next; + } + *list = NULL; +} diff --git a/linked-list/src/linkedList.h b/linked-list/src/linkedList.h new file mode 100644 index 0000000..c50610f --- /dev/null +++ b/linked-list/src/linkedList.h @@ -0,0 +1,13 @@ +#ifndef MY_LINKED_LIST_H +#define MY_LINKED_LIST_H + +typedef struct list_node { + int value; + struct list_node *next; +} *LinkedList; + +LinkedList createLinkedList(void); + +void freeLinkedList(LinkedList *list); + +#endif // MY_LINKED_LIST_H diff --git a/linked-list/test/testLinkedList.c b/linked-list/test/testLinkedList.c new file mode 100644 index 0000000..684fb78 --- /dev/null +++ b/linked-list/test/testLinkedList.c @@ -0,0 +1,11 @@ +#include "linkedList.h" + +#include +#include + +int main(void) { + LinkedList list = createLinkedList(); + freeLinkedList(&list); + printf("Success!\n"); + return 0; +}