-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstmap_bonus.c
42 lines (39 loc) · 1.42 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: aelsayed <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/31 10:46:31 by aelsayed #+# #+# */
/* Updated: 2025/01/29 11:31:40 by aelsayed ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
t_list *ft_lstmap_bonus(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new_lst;
t_list *new_node;
t_list *update;
new_lst = NULL;
if (!lst || !del || !f)
return (NULL);
while (lst)
{
new_node = (t_list *)malloc(sizeof(t_list));
if (!new_node)
{
ft_lstclear_bonus(&new_lst, del);
return (NULL);
}
new_node->content = f(lst->content);
new_node->next = NULL;
if (!new_lst)
new_lst = new_node;
else
update->next = new_node;
lst = lst->next;
update = new_node;
}
return (new_lst);
}