-
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.37 KB
/
ft_lstmap.c
File metadata and controls
41 lines (38 loc) · 1.37 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: mikkayma <mikkayma@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/21 13:21:38 by mikkayma #+# #+# */
/* Updated: 2024/10/22 11:24:14 by mikkayma ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *newlist;
t_list *newnode;
void *new_content;
newlist = NULL;
while (lst != NULL)
{
new_content = (*f)(lst->content);
if (!new_content)
{
ft_lstclear(&newlist, del);
return (NULL);
}
newnode = ft_lstnew(new_content);
if (!newnode)
{
ft_lstclear(&newlist, del);
del(new_content);
return (NULL);
}
ft_lstadd_back(&newlist, newnode);
lst = lst->next;
}
return (newlist);
}