-
Notifications
You must be signed in to change notification settings - Fork 0
/
cover.c
81 lines (72 loc) · 1.7 KB
/
cover.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* cover.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cquillet <cquillet@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/28 17:15:49 by cquillet #+# #+# */
/* Updated: 2016/11/30 22:22:16 by cquillet ### ########.fr */
/* */
/* ************************************************************************** */
#include "fillit.h"
void cover_col(t_node *n, int col)
{
int i;
int j;
n[n[col].r].l = n[col].l;
n[n[col].l].r = n[col].r;
i = n[col].d;
while (i != col)
{
j = n[i].r;
while (j != i)
{
n[n[j].d].u = n[j].u;
n[n[j].u].d = n[j].d;
n[n[j].c].nb_elem--;
j = n[j].r;
}
i = n[i].d;
}
}
void uncover_col(t_node *n, int col)
{
int i;
int j;
i = n[col].u;
while (i != col)
{
j = n[i].l;
while (j != i)
{
n[n[j].c].nb_elem++;
n[n[j].d].u = j;
n[n[j].u].d = j;
j = n[j].l;
}
i = n[i].u;
}
n[n[col].r].l = col;
n[n[col].l].r = col;
}
void cover_row(t_node *n, int row)
{
int j;
j = n[row].r;
while (j != row)
{
cover_col(n, n[j].c);
j = n[j].r;
}
}
void unvover_row(t_node *n, int row)
{
int j;
j = n[row].l;
while (j != row)
{
uncover_col(n, n[j].c);
j = n[j].l;
}
}