-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdancinglinks.cpp
138 lines (119 loc) · 2.67 KB
/
dancinglinks.cpp
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#include "dancinglinks.h"
#include <string>
using namespace std;
// Remove all rows in p's list from the other column lists they are
// in.
void Link::cover(Link* p) {
p->getR()->setL(p->getL());
p->getL()->setR(p->getR());
// Iterate through the items in p's column.
for (Link* i = p->getD(); i != p; i = i->getD()) {
// Iterate through the items in i's row and remove them from their
// respective columm list.
for (Link* j = i->getR(); j != i; j = j->getR()) {
j->getD()->setU(j->getU());
j->getU()->setD(j->getD());
}
}
}
// Reverse everything done by cover.
void Link::uncover(Link* p) {
for (Link* i = p->getU(); i != p; i = i->getU()) {
for (Link* j = i->getL(); j != i; j = j->getL()) {
j->getD()->setU(j);
j->getU()->setD(j);
}
}
p->getR()->setL(p);
p->getL()->setR(p);
}
Link::Link(Link* above, Link* left, Link* C, string N) {
if (above) {
if (above->getD()) {
above->getD()->setU(this);
setD(above->getD());
}
above->setD(this);
setU(above);
}
else {
setD(this);
setU(this);
}
if (left) {
if (left->getR()) {
left->getR()->setL(this);
setR(left->getR());
}
left->setR(this);
setL(left);
}
else {
setL(this);
setR(this);
}
setC(C);
Name = N;
}
Link* Link::getL() {
return LLink;
}
string Link::getN() {
return Name;
}
Link* Link::getR() {
return RLink;
}
Link* Link::getD() {
return DLink;
}
Link* Link::getU() {
return ULink;
}
Link* Link::getC() {
return CLink;
}
void Link::setL(Link* L) {
LLink = L;
}
void Link::setR(Link* R) {
RLink = R;
}
void Link::setD(Link* D) {
DLink = D;
}
void Link::setU(Link* U) {
ULink = U;
}
void Link::setC(Link* C) {
CLink = C;
}
////////////////////////////////////////////////////
// void Link::remove() { //
// Link* col = this->getD(); //
// while (col != this) { //
// Link* row = col->getR(); //
// while (row != this) { //
// row->getL()->setR(row->getR()); //
// row->getR()->setL(row->getL()); //
// row = row->getR(); //
// } //
// col->getU()->setD(col->getD()); //
// col->getD()->setU(col->getU()); //
// col = col->getD(); //
// } //
// } //
////////////////////////////////////////////////////
/////////////////////////////
// void Link::add() { //
// Link* ptr = this; //
// Link* l = getL(); //
// Link* r = getR(); //
// setR(l) = ptr; //
// setL(r) = ptr; //
// prt = ptr->getU(); //
// while (ptr != this) { //
// Link* q = ptr - 1; //
// while (q != ptr) { //
// Link* x = //
/////////////////////////////