aboutsummaryrefslogtreecommitdiff
path: root/c12/ex12/ft_list_remove_if.c
diff options
context:
space:
mode:
Diffstat (limited to 'c12/ex12/ft_list_remove_if.c')
-rw-r--r--c12/ex12/ft_list_remove_if.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/c12/ex12/ft_list_remove_if.c b/c12/ex12/ft_list_remove_if.c
index e69de29..dc7f310 100644
--- a/c12/ex12/ft_list_remove_if.c
+++ b/c12/ex12/ft_list_remove_if.c
@@ -0,0 +1,30 @@
+/* ************************************************************************** */
+/* */
+/* ::: :::::::: */
+/* ft_list_remove_if.c :+: :+: :+: */
+/* +:+ +:+ +:+ */
+/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
+/* +#+#+#+#+#+ +#+ */
+/* Created: 2019/07/19 08:38:28 by cacharle #+# #+# */
+/* Updated: 2019/07/19 08:49:43 by cacharle ### ########.fr */
+/* */
+/* ************************************************************************** */
+
+void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)(), void (*free_fct)(void *))
+{
+ t_list *prev;
+ t_list *cursor;
+
+ prev = NULL;
+ cursor = *begin_list;
+ while (cursor)
+ {
+ if ((*cmp)(cursor->data, data_ref))
+ {
+ if (prev)
+ prev->next = cursor->next;
+ (*free_fct)(cursor->data);
+ }
+ cursor = cursor->next;
+ }
+}