From b23760c78e2d087d84311925f2c014aa7c4c1635 Mon Sep 17 00:00:00 2001 From: Dominik Kaiser Date: Mon, 11 Mar 2024 13:26:26 +0100 Subject: [PATCH] lstmap --- ft_lstclear_bonus.c | 2 +- ft_lstmap_bonus.c | 29 ++++++++++++++++++----------- ft_lstnew_bonus.c | 4 ++-- libft.h | 2 +- 4 files changed, 22 insertions(+), 15 deletions(-) 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