-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_iteri.c
executable file
·60 lines (56 loc) · 2.13 KB
/
list_iteri.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_iteri.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/22 19:31:32 by akharrou #+# #+# */
/* Updated: 2019/03/04 13:17:20 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** list_iteri -- iterate through a list applying a function to every
** item of the list; additionally the index of the item
** in the list is passed to the function.
**
** SYNOPSIS
** #include <../libft.h>
**
** void
** list_iteri(t_list *head, void (*f)(unsigned int i, void *item));
**
** PARAMETERS
**
** t_list *head Pointer to the first
** element of a list.
**
** void (*f)(unsigned int i, void *item) A pointer to a function
** that takes a list item
** as parameter and the
** index of that item
** in the list.
**
** DESCRIPTION
** Iterates through a list applying the function 'f()' to all
** of its items.
**
** RETURN VALUES
** Returns nothing.
*/
#include "../Includes/list.h"
void list_iteri(t_list *head, void (*f)(unsigned int i, void *item))
{
unsigned int i;
if (f)
{
i = 0;
while (head)
{
f(i, head->item);
head = head->next;
++i;
}
}
}