-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_lstiter.c
82 lines (71 loc) · 2.17 KB
/
ft_lstiter.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sde-silv <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/04 13:49:29 by sde-silv #+# #+# */
/* Updated: 2023/10/04 13:57:04 by sde-silv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
void ft_multiplier(void *content)
{
*(int *)content = *(int *)content * 1000;
}
*/
void ft_lstiter(t_list *lst, void (*f)(void *))
{
while (lst)
{
(f)(lst->content);
lst = lst->next;
}
}
/*
int main(void)
{
t_list *head;
t_list *current;
t_list **lst;
t_list *last;
int size;
int *one;
int *two;
int *three;
int *four;
one = (int *)malloc(sizeof(int) * 1);
two = (int *)malloc(sizeof(int) * 1);
three = (int *)malloc(sizeof(int) * 1);
four = (int *)malloc(sizeof(int) * 1);
*one = 20;
*two = 30;
*three = 10;
*four = 40;
head = ft_lstnew((void *)one);
*lst = head;
head->next = ft_lstnew((void *)two);
ft_lstadd_front(lst, ft_lstnew((void *)three));
ft_lstadd_back(lst, ft_lstnew((void *)four));
current = *lst;
size = ft_lstsize(*lst);
printf("size: %d\n", size);
while (current != NULL)
{
printf("%zu\n", *(size_t *)(current->content));
current = current->next;
}
last = ft_lstlast(*lst);
printf("last: %zu\n", *(size_t *)(last->content));
ft_lstiter(*lst, ft_multiplier);
current = *lst;
while (current != NULL)
{
printf("%zu\n", *(size_t *)current->content);
current = current->next;
}
return (0);
}
*/