-
Notifications
You must be signed in to change notification settings - Fork 0
/
list_getitem.c
executable file
·56 lines (52 loc) · 2.12 KB
/
list_getitem.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_getitem.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: akharrou <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/02/23 17:26:10 by akharrou #+# #+# */
/* Updated: 2019/06/08 14:05:49 by akharrou ### ########.fr */
/* */
/* ************************************************************************** */
/*
** NAME
** list_getitem -- retrieve an item found at a specific reference.
**
** SYNOPSIS
** #include <../libft.h>
**
** void *
** list_getitem(t_list *head, const void *item_ref, int (*cmp)());
**
** PARAMETERS
**
** t_list *head Pointer to the first element of
** a list.
**
** const void *item_ref A reference to find the item.
**
** int (*cmp)(void *, void *) A comparasion function to compare the
** current item and the item reference.
** Returns 0 for a match.
**
** DESCRIPTION
** Iterates through a list until the specified item reference is
** matched according to the comparative function, then returns
** a pointer to the item.
**
** RETURN VALUES
** If successfully found, the item is returned; otherwise NULL is
** returned.
*/
#include "../Includes/stdlib_42.h"
#include "../Includes/list.h"
void *list_getitem(t_list *head, const void *item_ref,
int (*cmp)(const void *, const void *))
{
t_list *elem;
elem = list_getelem(head, item_ref, cmp);
if (elem)
return (elem->item);
return (NULL);
}