add: lst
This commit is contained in:
parent
4b5ee8bf10
commit
949cbd7355
@ -8,7 +8,7 @@ typedef struct s_lst
|
||||
} lst;
|
||||
|
||||
size_t lst_len(const lst* root);
|
||||
void lst_iter(const lst* root, void (*f)(void *));
|
||||
lst* lst_find(lst* root, void (*cmp)(const lst* lst1, const lst* lst2));
|
||||
void lst_iter(lst** root, void (*f)(void *));
|
||||
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_clear(lst** root, void (*del)(void *));
|
||||
|
18
src/lst/lst_addback.c
Normal file
18
src/lst/lst_addback.c
Normal 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
14
src/lst/lst_find.c
Normal 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
12
src/lst/lst_iter.c
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user