/* ************************************************************************** */ /* */ /* ::: :::::::: */ /* ft_list_remove_if.c :+: :+: :+: */ /* +:+ +:+ +:+ */ /* By: jhalford +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2016/08/14 13:37:44 by jhalford #+# #+# */ /* Updated: 2016/08/14 13:48:01 by jhalford ### ########.fr */ /* */ /* ************************************************************************** */ #include #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; } } }