-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap_bonus.c
More file actions
35 lines (32 loc) · 1.4 KB
/
ft_lstmap_bonus.c
File metadata and controls
35 lines (32 loc) · 1.4 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: acastrov <acastrov@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/03 17:36:10 by acastrov #+# #+# */
/* Updated: 2024/10/03 18:56:26 by acastrov ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// Creates new list with f ft applied in all node contents, del clear if needed
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *list_head;
t_list *list_node;
list_head = NULL;
as we don - t need lo allocate with listadd while (lst)
{
list_node = ft_lstnew(lst->content);
if (!list_node)
{
ft_lstclear(&list_head, del);
return (NULL);
}
list_node->content = f(list_node->content);
ft_lstadd_back(&list_head, list_node);
lst = lst->next;
}
return (list_head);
}