-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap.c
More file actions
50 lines (46 loc) · 1.48 KB
/
Copy pathft_lstmap.c
File metadata and controls
50 lines (46 loc) · 1.48 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
42
43
44
45
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstmap.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: kjurkows <kjurkows@student.42warsaw.pl> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/19 16:52:40 by kjurkows #+# #+# */
/* Updated: 2026/06/25 17:41:13 by kjurkows ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//# Part 3
//## linked list
//import `malloc`, `free`
#include <stdlib.h>
/** @brief map a list
*
* @param lst first node of a list to map
* @param f function used for mapping
* @param del function used to delete content
* @return new list
*/
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *new;
t_list *tmp;
if (!f)
return (0);
new = 0;
while (lst)
{
if (lst->content)
{
tmp = ft_lstnew(f(lst->content));
if (!tmp)
{
ft_lstclear(&new, del);
return (0);
}
ft_lstadd_back(&new, tmp);
}
lst = lst->next;
}
return (new);
}