-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist_utils.c
72 lines (63 loc) · 1.6 KB
/
list_utils.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list_utils.h :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: obenazzo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 10:54:33 by obenazzo #+# #+# */
/* Updated: 2017/11/08 10:54:40 by obenazzo ### ########.fr */
/* */
/* ************************************************************************** */
#include "lem_in.h"
int i_in_list(t_list *t, char *s)
{
int i;
i = -1;
while (t)
{
i++;
if (!ft_strcmp(t->DATA, s))
return (i);
t = t->next;
}
return (-1);
}
int int_i_in_list(t_list *t, int n)
{
int i;
i = -1;
while (t)
{
i++;
if (*(int *)t->DATA == n)
return (i);
t = t->next;
}
return (-1);
}
void ft_list_push_back(t_list **l, void *content, int content_size)
{
t_list *temp;
temp = *l;
if (temp)
{
while (temp->next)
temp = temp->next;
if (!(temp->next = ft_lstnew(content, content_size)))
error();
}
else if (!(*l = ft_lstnew(content, content_size)))
error();
}
void free_list(t_list *l)
{
t_list *t;
while (l)
{
t = l->next;
pr_free(l->DATA);
pr_free(l);
l = t;
}
}