-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap.c
More file actions
41 lines (38 loc) · 1.35 KB
/
ft_lstmap.c
File metadata and controls
41 lines (38 loc) · 1.35 KB
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
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edforte <edforte@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/22 17:15:01 by edforte #+# #+# */
/* Updated: 2024/01/23 19:57:58 by edforte ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new;
t_list *p;
t_list *cpy;
if (!lst || !f || !del)
return (NULL);
new = (ft_lstnew(f(lst->content)));
cpy = new;
if (!new)
{
ft_lstclear(&new, del);
return (NULL);
}
p = lst;
lst = lst->next;
while (lst)
{
new->next = ft_lstnew(f(lst->content));
if (!new->content)
return (ft_lstclear(&p, del), NULL);
lst = lst->next;
new = new->next;
}
return (cpy);
}