aboutsummaryrefslogtreecommitdiff
path: root/src/lst/ft_lstremove_if.c
blob: 488539efddc432a6cd3f7ff943a53e90fe325eea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_lstremove_if.c                                  :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: cacharle <marvin@42.fr>                    +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2020/01/30 09:36:49 by cacharle          #+#    #+#             */
/*   Updated: 2020/02/16 03:57:07 by cacharle         ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#include "libft.h"
#include "libft_lst.h"

void	ft_lstremove_if(t_ftlst **lst, t_ftcompar_func cmp,
						const void *ref, t_ftdel_func del)
{
	t_ftlst *saved_next;

	if (lst == NULL || *lst == NULL)
		return ;
	if (cmp((*lst)->content, ref) == 0)
	{
		saved_next = (*lst)->next;
		ft_lstdelone(*lst, del);
		*lst = saved_next;
		ft_lstremove_if(lst, cmp, ref, del);
		return ;
	}
	ft_lstremove_if(&(*lst)->next, cmp, ref, del);
}