-
Notifications
You must be signed in to change notification settings - Fork 0
/
list.c
72 lines (63 loc) · 1.28 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
/*
** list.c for in /home/karque_f//c/zappy-2015-2014s-marcha_j/Serveur
**
** Made by fabien karquel
** Login <[email protected]>
**
** Started on Mon Jun 4 15:22:36 2012 fabien karquel
** Last update Mon Jun 18 14:49:53 2012 hugo marchadier
*/
#include <unistd.h>
#include <stdlib.h>
#include "list.h"
#include "tab_sym.h"
#include "xfct.h"
static t_list *init_new_maillon(t_sym *data)
{
t_list *new;
new = xmalloc(sizeof(*new));
new->data = data;
new->next = NULL;
new->prev = NULL;
return (new);
}
t_list *add_maillon(t_list *list, t_sym *data)
{
t_list *new;
t_list *tmp;
new = init_new_maillon(data);
if (!list)
return (new);
tmp = list;
while (tmp->next)
tmp = tmp->next;
new->prev = tmp;
tmp->next = new;
return (list);
}
t_list *remove_maillon(t_list *list, t_list *to_rem)
{
t_list *tmp;
tmp = list;
if (tmp == NULL || to_rem == NULL)
return (tmp);
if (to_rem->prev == NULL && to_rem->next == NULL)
{
free(to_rem);
return (NULL);
}
if (to_rem->prev != NULL)
to_rem->prev->next = to_rem->next;
if (to_rem->next != NULL)
{
if (to_rem->prev != NULL)
to_rem->next->prev = to_rem->prev;
else
{
to_rem->next->prev = NULL;
tmp = to_rem->next;
}
}
free(to_rem);
return (tmp);
}