-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstmap.c
32 lines (29 loc) · 1.2 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rodrodri <[email protected] > +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/30 14:41:03 by rodrodri #+# #+# */
/* Updated: 2021/11/15 23:21:54 by rodrodri ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *mapped_lst;
t_list *tmp_node;
if (!lst || !f)
return (NULL);
mapped_lst = NULL;
while (lst)
{
tmp_node = f(lst);
if (!tmp_node)
return (NULL);
ft_lst_push_back(&mapped_lst, tmp_node);
lst = lst->next;
}
return (mapped_lst);
}