diff options
| author | Charles <sircharlesaze@gmail.com> | 2019-07-24 18:57:19 +0200 |
|---|---|---|
| committer | Charles <sircharlesaze@gmail.com> | 2019-07-24 18:57:19 +0200 |
| commit | 475449dd4b1f3308bac6f72c34d87812216a0738 (patch) | |
| tree | 319a76f0e87b041818156f2d1dfbbc6a7dfacf06 /exam02/rendu/ft_list_remove_if | |
| parent | 83edb77d74bb339f3e1324a51039c78ac503db90 (diff) | |
| download | piscine-475449dd4b1f3308bac6f72c34d87812216a0738.tar.gz piscine-475449dd4b1f3308bac6f72c34d87812216a0738.tar.bz2 piscine-475449dd4b1f3308bac6f72c34d87812216a0738.zip | |
exam02
Diffstat (limited to 'exam02/rendu/ft_list_remove_if')
| -rwxr-xr-x | exam02/rendu/ft_list_remove_if/ft_list_remove_if.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/exam02/rendu/ft_list_remove_if/ft_list_remove_if.c b/exam02/rendu/ft_list_remove_if/ft_list_remove_if.c new file mode 100755 index 0000000..57d627c --- /dev/null +++ b/exam02/rendu/ft_list_remove_if/ft_list_remove_if.c @@ -0,0 +1,38 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* ft_list_remove_if.c :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: exam <marvin@42.fr> +#+ +:+ +#+ */ +/* +#+#+#+#+#+ +#+ */ +/* Created: 2019/07/19 20:02:01 by exam #+# #+# */ +/* Updated: 2019/07/19 20:46:03 by exam ### ########.fr */ +/* */ +/* ************************************************************************** */ + +#include "ft_list.h" + +void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)()) +{ + t_list *cursor; + t_list *prev; + + if (!*begin_list) + return ; + while (*begin_list && (*cmp)(data_ref, (*begin_list)->data)) + *begin_list = (*begin_list)->next; + cursor = *begin_list; + prev = NULL; + while (cursor) + { + while (cursor && (*cmp)(data_ref, cursor->data)) + { + if (prev != NULL) + prev->next = cursor->next; + cursor = cursor->next; + } + prev = cursor; + if (cursor) + cursor = cursor->next; + } +} |
