Libft aortigos
This commit is contained in:
38
ft_lstmap_bonus.c
Normal file
38
ft_lstmap_bonus.c
Normal file
@@ -0,0 +1,38 @@
|
||||
/* ************************************************************************** */
|
||||
/* */
|
||||
/* ::: :::::::: */
|
||||
/* ft_lstmap.c :+: :+: :+: */
|
||||
/* +:+ +:+ +:+ */
|
||||
/* By: aortigos <aortigos@student.42malaga.com> +#+ +:+ +#+ */
|
||||
/* +#+#+#+#+#+ +#+ */
|
||||
/* Created: 2023/10/23 17:25:38 by aortigos #+# #+# */
|
||||
/* Updated: 2023/10/24 18:15:50 by aortigos ### ########.fr */
|
||||
/* */
|
||||
/* ************************************************************************** */
|
||||
|
||||
#include "libft.h"
|
||||
|
||||
t_list *ft_lstmap(t_list *lst, void *(f)(void *), void (*del)(void *))
|
||||
{
|
||||
t_list *x;
|
||||
t_list *new;
|
||||
void *set;
|
||||
|
||||
if (!lst || !f || !del)
|
||||
return (NULL);
|
||||
x = NULL;
|
||||
while (lst)
|
||||
{
|
||||
set = f(lst->content);
|
||||
new = ft_lstnew(set);
|
||||
if (!new)
|
||||
{
|
||||
del(set);
|
||||
ft_lstclear(&x, del);
|
||||
return (NULL);
|
||||
}
|
||||
ft_lstadd_back(&x, new);
|
||||
lst = lst->next;
|
||||
}
|
||||
return (x);
|
||||
}
|
||||
Reference in New Issue
Block a user