-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap.c
More file actions
38 lines (35 loc) · 1.29 KB
/
ft_lstmap.c
File metadata and controls
38 lines (35 loc) · 1.29 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: omaly <omaly@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/09/19 11:43:50 by omaly #+# #+# */
/* Updated: 2025/09/19 15:01:41 by omaly ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *head;
t_list *ptr;
if (!lst)
return (NULL);
head = ft_lstnew(f(lst->content));
ptr = head;
lst = lst->next;
while (lst)
{
ptr->next = ft_lstnew(f(lst->content));
if (!ptr->next)
{
ft_lstclear(&head, del);
return (NULL);
}
lst = lst->next;
ptr = ptr->next;
}
ptr->next = NULL;
return (head);
}