-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.cpp
81 lines (68 loc) · 1.41 KB
/
Cell.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
#include "Cell.h"
Cell::Cell(const int p_value, const bool p_given)
{
m_value = p_value;
m_given = p_given;
//Populating candidate list
for (int i = 1; i <= 9; ++i) {
m_candidateList.push_back(i);
}
}
Cell::~Cell()
{
}
Cell::Cell()
{
m_value = 0;
m_given = false;
//Populating candidate list
for (int i = 1; i <= 9; ++i) {
m_candidateList.push_back(i);
}
}
int Cell::getValue() const
{
return m_value;
}
bool Cell::isGiven() const
{
return m_given;
}
int Cell::getCandiListSize() const
{
return m_candidateList.size();
}
int Cell::getCandidateAt(int index) const
{
return m_candidateList[index];
}
void Cell::setValue(int newValue)
{
m_value = newValue;
}
void Cell::setGiven(bool newValue)
{
m_given = newValue;
}
void Cell::addCandidate(int newCandidate)
{
bool isDuplicate = false;
//Checking if item already exists in the list
for (size_t i = 0; i < m_candidateList.size(); ++i) {
if (m_candidateList[i] == newCandidate) {
isDuplicate = true;
}
}
if (!isDuplicate) {
m_candidateList.push_back(newCandidate);
}
}
void Cell::removeCandidate(int removalCandidate)
{
//Find the position of the element to remove and reomve it from that position
for (size_t i = 0; i < m_candidateList.size(); ++i) {
if (m_candidateList[i] == removalCandidate) {
m_candidateList.erase(m_candidateList.begin() + i);
}
}
}