46 lines
1.4 KiB
C
46 lines
1.4 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_list_remove_if.c :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: jhalford <marvin@42.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2016/08/14 13:37:44 by jhalford #+# #+# */
|
|
/* Updated: 2016/08/14 13:48:01 by jhalford ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#include <stdlib.h>
|
|
#include "ft_list.h"
|
|
|
|
void ft_list_remove_if(
|
|
t_list **begin_list,
|
|
void *data_ref,
|
|
int (*cmp)())
|
|
{
|
|
t_list *last;
|
|
t_list *current;
|
|
t_list *tmp;
|
|
|
|
last = NULL;
|
|
current = *begin_list;
|
|
tmp = NULL;
|
|
while (current)
|
|
{
|
|
if ((*cmp)(current->data, data_ref) == 0)
|
|
{
|
|
if (current == *begin_list)
|
|
*begin_list = current->next;
|
|
else
|
|
last->next = current->next;
|
|
tmp = current;
|
|
current = current->next;
|
|
free(tmp);
|
|
}
|
|
else
|
|
{
|
|
last = current;
|
|
current = current->next;
|
|
}
|
|
}
|
|
}
|