-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap_bonus.c
42 lines (39 loc) · 1.47 KB
/
ft_lstmap_bonus.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gmachado <gmachado@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/12 21:28:20 by gmachado #+# #+# */
/* Updated: 2022/04/20 15:14:15 by gmachado ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *tmp;
t_list *new_list;
if (lst == NULL || f == NULL)
return (NULL);
new_list = (t_list *)malloc(sizeof(t_list));
if (new_list == NULL)
return (NULL);
tmp = new_list;
tmp->content = (int *)f(lst->content);
lst = lst->next;
while (lst != NULL)
{
tmp->next = (t_list *)malloc(sizeof(t_list));
tmp = tmp->next;
if (tmp == NULL)
{
ft_lstclear(&new_list, del);
return (NULL);
}
tmp->content = (int *)f(lst->content);
lst = lst->next;
}
tmp->next = NULL;
return (new_list);
}