piscine/c12/ex12/ft_list_remove_if.c
Willem Haffmans 607ce08c18 all
2024-09-10 00:18:01 +02:00

44 lines
1.3 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_list_remove_if.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: whaffman <whaffman@student.codam.nl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/07/03 18:31:10 by whaffman #+# #+# */
/* Updated: 2024/07/03 18:56:38 by whaffman ### ########.fr */
/* */
/* ************************************************************************** */
#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 *curr;
t_list *next;
curr = *begin_list;
while (curr)
{
next = curr->next;
if (!cmp(curr->data, data_ref))
{
if (curr == *begin_list)
*begin_list = next;
else
prev->next = next;
free_fct(curr->data);
free(curr);
}
else
prev = curr;
curr = next;
}
}