-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstmap.c
58 lines (53 loc) · 1.67 KB
/
ft_lstmap.c
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
46
47
48
49
50
51
52
53
54
55
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/16 11:28:18 by tpouget #+# #+# */
/* Updated: 2020/05/28 10:40:30 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_list;
t_list *element;
if (!lst || !f)
return (NULL);
new_list = NULL;
while (lst)
{
element = ft_lstnew(f(lst->content));
if (!element)
{
ft_lstclear(&new_list, del);
return (NULL);
}
ft_lstadd_back(&new_list, element);
lst = lst->next;
}
return (new_list);
}
/*
t_list *ft_lstmap(t_list *lst, void *(*f)(void *),void (*del)(void *))
{
t_list *result;
t_list *element;
element = malloc(sizeof(t_list));
if (!element || !lst || !f)
return (NULL);
result = element;
while (lst && element)
{
element = (t_list*)f(lst);
lst = lst->next;
element = element->next;
element = malloc(sizeof(t_list));
if (!element)
ft_lstclear(&result, del);
}
return (result);
}
*/