-
Notifications
You must be signed in to change notification settings - Fork 0
/
IdList.cpp
69 lines (49 loc) · 970 Bytes
/
IdList.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
#include "IdList.h"
IdList::IdList(unsigned int n)
: _list(n), _N(0), _size(n)
{
}
int IdList::operator[] (unsigned int n)
{
Guarantee (n < _N, "Out of bounds access IdList(%u)::operator[%u]. Don't go over IdList::N().", _size, n);
return _list[n];
}
bool IdList::add(int value)
{
Guarantee(_N < _size, "Can't add items anymore to IdList(%u).", _size);
_list[_N] = value;
++_N;
return true;
}
bool IdList::del(int value)
{
for (unsigned int i = 0; i < _N; ++i)
{
if (_list[i] == value)
{
for (unsigned int j = i; j+1 < _N; ++j)
_list[j] = _list[j+1];
--_N;
return true;
}
}
return false;
}
bool IdList::has(int value)
{
for (unsigned int i=0; i < _N; ++i)
if (_list[i] == value)
return true;
return false;
}
void IdList::clear()
{
_list.clear();
_N = 0;
}
void IdList::print()
{
for (unsigned int i=0; i < _N; ++i)
std::cout << _list[i] << " ";
std::cout << std::endl;
}