aboutsummaryrefslogtreecommitdiff
path: root/c12/ex12
diff options
context:
space:
mode:
authorCabergs Charles <cacharle@e-r6-p7.s19.be>2019-07-24 08:02:55 +0200
committerCabergs Charles <cacharle@e-r6-p7.s19.be>2019-07-24 08:02:55 +0200
commite7acdc820fefa41ae00a7c776388e3d17250a2e9 (patch)
tree5604e51c0008088f25b2f5dfb9143a852dd079dd /c12/ex12
parent454d82f30e354e2629563822bac637e5eaa8e4ff (diff)
downloadpiscine-e7acdc820fefa41ae00a7c776388e3d17250a2e9.tar.gz
piscine-e7acdc820fefa41ae00a7c776388e3d17250a2e9.tar.bz2
piscine-e7acdc820fefa41ae00a7c776388e3d17250a2e9.zip
c12 passed, c13 start
Diffstat (limited to 'c12/ex12')
-rw-r--r--c12/ex12/ft_list.h4
-rw-r--r--c12/ex12/ft_list_remove_if.c26
2 files changed, 22 insertions, 8 deletions
diff --git a/c12/ex12/ft_list.h b/c12/ex12/ft_list.h
index 0f7f09a..3edec35 100644
--- a/c12/ex12/ft_list.h
+++ b/c12/ex12/ft_list.h
@@ -6,12 +6,12 @@
/* By: cacharle <charles.cabergs@gmail.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/07/09 14:33:17 by cacharle #+# #+# */
-/* Updated: 2019/07/19 08:26:52 by cacharle ### ########.fr */
+/* Updated: 2019/07/23 15:21:53 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
#ifndef FT_LIST_H
-#define FT_LIST_H
+# define FT_LIST_H
typedef struct s_list
{
diff --git a/c12/ex12/ft_list_remove_if.c b/c12/ex12/ft_list_remove_if.c
index dc7f310..c6821b8 100644
--- a/c12/ex12/ft_list_remove_if.c
+++ b/c12/ex12/ft_list_remove_if.c
@@ -6,25 +6,39 @@
/* 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 */
+/* Updated: 2019/07/23 15:41:03 by cacharle ### ########.fr */
/* */
/* ************************************************************************** */
-void ft_list_remove_if(t_list **begin_list, void *data_ref, int (*cmp)(), void (*free_fct)(void *))
+#include <stdlib.h>
+#include "ft_list.h"
+
+void ft_list_remove_if(t_list **begin_list, void *data_ref,
+ int (*cmp)(), void (*free_fct)(void *))
{
t_list *prev;
t_list *cursor;
+ t_list *tmp;
prev = NULL;
cursor = *begin_list;
- while (cursor)
+ while (cursor != NULL)
{
- if ((*cmp)(cursor->data, data_ref))
+ while (cursor && (*cmp)(cursor->data, data_ref) == 0)
{
- if (prev)
+ if (prev != NULL)
prev->next = cursor->next;
+ else
+ *begin_list = cursor->next;
(*free_fct)(cursor->data);
+ tmp = cursor;
+ cursor = cursor->next;
+ free(tmp);
+ }
+ if (cursor != NULL)
+ {
+ prev = cursor;
+ cursor = cursor->next;
}
- cursor = cursor->next;
}
}