From: Dominik Kaiser Date: Mon, 11 Mar 2024 12:26:26 +0000 (+0100) Subject: lstmap X-Git-Url: https://git.dkaiser.de/?a=commitdiff_plain;h=b23760c78e2d087d84311925f2c014aa7c4c1635;p=42%2Flibft.git lstmap --- diff --git a/ft_lstclear_bonus.c b/ft_lstclear_bonus.c index 9af095e..f661fc9 100644 --- a/ft_lstclear_bonus.c +++ b/ft_lstclear_bonus.c @@ -6,7 +6,7 @@ /* By: dkaiser content)); - if (!new) + content = f(lst->content); + cur_new = ft_lstnew(content); + if (!cur_new) { - free(new); + del(content); return (NULL); } - result = new; + result = cur_new; + if (!lst->next) + return (result); lst = lst->next; while (lst) { - new->next = ft_lstnew(f(lst->content)); - if (!new->next) + content = f(lst->content); + cur_new->next = ft_lstnew(content); + if (!cur_new->next) { - ft_lstclear(&new, del); + del(content); + ft_lstclear(&result, del); return (NULL); } - new = new->next; + if (!lst->next) + return (result); lst = lst->next; + cur_new = cur_new->next; } - // new->next = NULL; return (result); } diff --git a/ft_lstnew_bonus.c b/ft_lstnew_bonus.c index a8f43ce..eeb6030 100644 --- a/ft_lstnew_bonus.c +++ b/ft_lstnew_bonus.c @@ -6,7 +6,7 @@ /* By: dkaiser content = content; result->next = NULL; return (result); diff --git a/libft.h b/libft.h index 1256bdc..148094f 100644 --- a/libft.h +++ b/libft.h @@ -6,7 +6,7 @@ /* By: dkaiser