This commit is contained in:
starnakin 2023-06-28 10:46:44 +02:00
parent 4b5ee8bf10
commit 949cbd7355
4 changed files with 46 additions and 2 deletions

View File

@ -8,7 +8,7 @@ typedef struct s_lst
} lst; } lst;
size_t lst_len(const lst* root); size_t lst_len(const lst* root);
void lst_iter(const lst* root, void (*f)(void *)); void lst_iter(lst** root, void (*f)(void *));
lst* lst_find(lst* root, void (*cmp)(const lst* lst1, const lst* lst2)); lst* lst_find(lst** root, const lst* to_find, int (*cmp)(const lst* lst1, const lst* lst2));
void lst_addback(lst** root, lst* nouveau); void lst_addback(lst** root, lst* nouveau);
void lst_clear(lst** root, void (*del)(void *)); void lst_clear(lst** root, void (*del)(void *));

18
src/lst/lst_addback.c Normal file
View File

@ -0,0 +1,18 @@
#include "lst.h"
void lst_addback(lst **root, lst *nouveau)
{
lst* current = *root;
if (root == NULL || nouveau == NULL)
return;
nouveau->next = NULL;
if (current == NULL)
{
current = nouveau;
return;
}
while (current->next != NULL)
current = current->next;
current->next = nouveau;
}

14
src/lst/lst_find.c Normal file
View File

@ -0,0 +1,14 @@
#include "./lst.h"
lst* lst_find(lst** root, const lst* to_find, int (*cmp)(const lst* lst1, const lst* lst2))
{
lst* current = *root;
while (current != NULL)
{
if ((*cmp)(to_find, current) == 0)
return current;
current = current->next;
}
return (NULL);
}

12
src/lst/lst_iter.c Normal file
View File

@ -0,0 +1,12 @@
#include "./lst.h"
void lst_iter(lst** root, void (*f)(void *))
{
lst *current = *root;
while (current != NULL)
{
(*f)(current);
current = current->next;
}
}