-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstmap_bonus.c
38 lines (35 loc) · 1.28 KB
/
ft_lstmap_bonus.c
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
33
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: apimikov <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/13 08:02:25 by apimikov #+# #+# */
/* Updated: 2023/11/13 15:16:20 by apimikov ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *list;
t_list *node;
void *temp;
if (!lst || !f || !del)
return (NULL);
list = NULL;
while (lst)
{
temp = f(lst->content);
node = ft_lstnew(temp);
if (!node)
{
ft_lstclear(&list, del);
del(temp);
return (NULL);
}
ft_lstadd_back(&list, node);
lst = lst->next;
}
return (list);
}