-
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.37 KB
/
ft_lstmap.c
File metadata and controls
41 lines (38 loc) · 1.37 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: ommohame < ommohame@student.42abudhabi.ae> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/09 23:27:42 by ommohame #+# #+# */
/* Updated: 2022/01/12 23:24:09 by ommohame ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
* makes a new list
* applies f function on old lst content then saves it in the new list
* uses del function if content is NULL
* returns the new list
*/
t_list *ft_lstmap(t_list *lst, void *(*f)(void *), void (*del)(void *))
{
t_list *tmp;
t_list *new;
if (!lst || !f)
return (0);
new = 0;
while (lst)
{
tmp = ft_lstnew(f(lst -> content));
if (!tmp)
{
ft_lstclear(&new, del);
return (0);
}
ft_lstadd_back(&new, tmp);
lst = lst -> next;
}
return (new);
}