Projet de l'école 42 : Libft
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
1.2 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
3 years ago
/* ft_lstmap.c :+: :+: :+: */
3 years ago
/* +:+ +:+ +:+ */
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 14:54:31 by narnaud #+# #+# */
3 years ago
/* Updated: 2022/03/24 11:31:05 by narnaud ### ########.fr */
3 years ago
/* */
/* ************************************************************************** */
#include "../libft.h"
3 years ago
t_slist *ft_slst_map(t_slist *lst, void *(*f)(void *), void (*del)(void *))
3 years ago
{
3 years ago
t_slist *new_lst;
3 years ago
if (!lst || !f)
return (NULL);
3 years ago
new_lst = ft_slst_new((*f)(lst->content));
3 years ago
if (!new_lst)
{
3 years ago
ft_slst_clear(&new_lst, del);
3 years ago
return (NULL);
}
3 years ago
new_lst->next = ft_slst_map(lst->next, f, del);
3 years ago
return (new_lst);
}