-
Notifications
You must be signed in to change notification settings - Fork 0
/
node.c
executable file
·75 lines (66 loc) · 1.58 KB
/
node.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* node.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: staeter <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/20 16:34:43 by staeter #+# #+# */
/* Updated: 2019/01/12 13:42:57 by nraziano ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void free_node(t_node **n)
{
t_node *t;
if (*n)
{
t = (*n)->next;
free_tetri(&(*n)->te);
free(*n);
if (t != NULL)
{
*n = t;
free_node(&t);
}
else
*n = NULL;
}
}
t_node *new_node(void)
{
t_node *dest;
if (!(dest = (t_node *)malloc(sizeof(t_node))))
return (NULL);
dest->next = NULL;
dest->te = NULL;
return (dest);
}
t_boolean add_node(t_node **n, t_tetri *te)
{
t_node *dest;
t_node *t;
if (!te || !(dest = new_node()))
return (0);
dest->te = te;
if (!*n)
*n = dest;
else
{
t = *n;
while (t->next)
t = t->next;
t->next = dest;
}
return (1);
}
void rm_node(t_node **n)
{
t_node *t;
if (!*n)
{
t = (*n)->next;
free(*n);
*n = t;
}
}