-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_lstiter.c
49 lines (48 loc) · 1.91 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_lstiter.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oostapen <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/15 18:18:19 by oostapen #+# #+# */
/* Updated: 2024/04/15 18:23:43 by oostapen ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
* Function: ft_lstiter
* --------------------
* Iterates the list 'lst' and applies the function 'f'
* to the content of each element.
*
* lst: a pointer to the first element of the list
* f: a pointer to the function to be applied to the
* content of each element
*
* This function first checks if `lst` or `f` is NULL.
* If so, it does nothing and simply returns.
*
* If `lst` and `f` are not NULL, the function enters
* a `while` loop, which continues until the list
* becomes NULL (i.e., all elements of the list have
* been processed).
*
* Inside the loop, the function calls the function 'f'
* on the 'content' of the current element, and then
* moves on to the next element by setting 'lst' equal
* to 'lst->next'.
*
* Thus, the function goes through the entire list,
* applying the function 'f' to the content of each element.
*/
void ft_lstiter(t_list *lst, void (*f)(void *))
{
if (lst == NULL || f == NULL)
return ;
while (lst != NULL)
{
f(lst->content);
lst = lst->next;
}
}