-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap.c
More file actions
41 lines (38 loc) · 1.33 KB
/
Copy pathft_lstmap.c
File metadata and controls
41 lines (38 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: user <user@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/29 15:30:00 by user #+# #+# */
/* Updated: 2023/04/29 15:30:00 by user ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new;
t_list *head;
t_list *tail;
if (!lst || !f || !del)
return (NULL);
head = ft_lstnew(f(lst->content));
if (!head)
return (NULL);
tail = head;
lst = lst->next;
while (lst)
{
new = ft_lstnew(f(lst->content));
if (!new)
{
ft_lstclear(&head, del);
return (NULL);
}
tail->next = new;
tail = new;
lst = lst->next;
}
return (head);
}