-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap.c
executable file
·41 lines (38 loc) · 1.54 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mberger <mberger@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2014/12/23 20:39:33 by mberger #+# #+# */
/* Updated: 2014/12/23 20:42:33 by mberger ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, t_list *(*f)(t_list *elem))
{
t_list *brand_new_list;
t_list *the_beginning;
t_list *tempo;
if (f == NULL && lst == NULL)
return (NULL);
tempo = f(lst);
brand_new_list = ft_lstnew(tempo->content, tempo->content_size);
if (brand_new_list == NULL)
return (NULL);
the_beginning = brand_new_list;
while (lst->next != NULL)
{
tempo = f(lst->next);
brand_new_list->next = ft_lstnew(tempo->content, tempo->content_size);
if (brand_new_list->next == NULL)
{
ft_lstdel(&the_beginning, &ft_bzero);
return (NULL);
}
lst = lst->next;
brand_new_list = brand_new_list->next;
}
return (the_beginning);
}