-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_lstmap.c
More file actions
42 lines (38 loc) · 1.52 KB
/
ft_lstmap.c
File metadata and controls
42 lines (38 loc) · 1.52 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_lstmap.c :+: :+: */
/* +:+ */
/* By: farodrig <farodrig@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2021/01/09 14:16:48 by farodrig #+# #+# */
/* Updated: 2021/02/28 22:08:44 by farodrig ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
#include <stdlib.h>
/*
** Iterates the list 'lst' and applies the function 'f' to the content of each
** element. Creates a newlist resulting of the successive applications of the
** function 'f'. The 'del' function is used to delete the content of an
** element if needed
*/
t_list *ft_lstmap(t_list *list, void *(*f)(void *), void (*del)(void *))
{
t_list *map_list;
int lst_size;
(void)del;
if (!list)
{
return (0);
}
lst_size = ft_lstsize(list);
map_list = ft_lstnew(f(list->content));
list = list->next;
while (list)
{
ft_lstadd_back(&map_list, ft_lstnew(f(list->content)));
list = list->next;
}
return (&map_list[0]);
}