-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap_bonus.c
More file actions
45 lines (40 loc) · 1.46 KB
/
ft_lstmap_bonus.c
File metadata and controls
45 lines (40 loc) · 1.46 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
42
43
44
45
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: joramire <joramire@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/03 16:19:34 by joramire #+# #+# */
/* Updated: 2022/10/03 18:35:01 by joramire ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static t_list *ft_f(void *content, void *(*f)(void *))
{
t_list *node;
node = malloc(sizeof(t_list));
if (node == NULL)
return (NULL);
node -> content = f(content);
node -> next = NULL;
return (node);
}
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *nlst;
t_list *aux;
if (lst == NULL)
return (NULL);
nlst = ft_f(lst -> content, f);
lst = lst -> next;
while (lst != NULL)
{
aux = ft_f(lst -> content, f);
if (aux == NULL)
ft_lstclear(&nlst, del);
ft_lstadd_back(&nlst, aux);
lst = lst -> next;
}
return (nlst);
}