-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap_bonus.c
More file actions
37 lines (34 loc) · 1.33 KB
/
ft_lstmap_bonus.c
File metadata and controls
37 lines (34 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ymassiou <ymassiou@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/08 17:32:40 by ymassiou #+# #+# */
/* Updated: 2023/11/22 14:08:27 by ymassiou ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *result;
t_list *result_head;
if (!lst || !f || !del)
return (NULL);
result = NULL;
result_head = NULL;
while (lst != NULL)
{
result = ft_lstnew(NULL);
if (result == NULL)
{
ft_lstclear(&result_head, del);
return (NULL);
}
result->content = f(lst->content);
ft_lstadd_back(&result_head, result);
lst = lst->next;
}
return (result_head);
}