-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlist.c
85 lines (81 loc) · 2.03 KB
/
list.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
83
84
85
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* list.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eleclet <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/01/13 12:30:47 by eleclet #+# #+# */
/* Updated: 2016/01/17 19:54:22 by eleclet ### ########.fr */
/* */
/* ************************************************************************** */
#include "list.h"
t_lst *add(t_lst *liste, char *s, int index)
{
t_lst *tmp;
tmp = malloc(sizeof(t_lst));
tmp->data = malloc(sizeof(t_data));
if (tmp)
{
tmp->data->s = s;
tmp->index = index;
tmp->next = liste;
}
return (tmp);
}
t_lst *try(t_lst *liste, char *s ,int index)
{
return (liste);
}
void printlist(t_lst *lst)
{
printf("s = %s and i = %d\n", lst->data->s, lst->index);
lst = lst->next;
}
void insert(t_lst *liste, char *s, int index)
{
while (liste->next != NULL)
{
liste = liste->next;
}
liste->next = (t_lst *)malloc(sizeof(t_lst));
liste = liste->next;
liste->next =NULL;
liste->index = index;
liste->data = (t_data *)malloc(sizeof(t_data));
liste->data->s =NULL;
}
void print(t_lst *liste)
{
if (!liste)
{
return;
}
printf("index = %d\n", liste->index);
print(liste->next);
}
t_lst *find(t_lst *liste, int i)
{
while (liste)
{
printf("liste->i %d\n",liste->index);
if (liste->index == i)
return (liste);
liste = liste->next;
}
return (0);
}
void del(t_lst *liste)
{
t_lst *tmp;
while (liste)
{
tmp = liste;
free(tmp->data);
liste = liste->next;
free(tmp);
tmp = NULL;
}
}
//void change
//t_lst lsthead()