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 |
#include "KeyValueLijst.h"
KeyValueLijst::KeyValueLijst():m_AantalElementen(0), m_Capaciteit(BASE_SIZE)
{
m_KeyValueArrPtr = new KeyValuePaar[BASE_SIZE];
}
KeyValueLijst::~KeyValueLijst()
{
delete[] m_KeyValueArrPtr;
}
void KeyValueLijst::insert(KeyValuePaar value)
{
if(m_AantalElementen>=m_Capaciteit)
{
vergrootArray();
}
m_KeyValueArrPtr[m_AantalElementen] = value;
m_AantalElementen++;
}
tstring KeyValueLijst::find(tstring key)
{
for(int i=0;i<m_AantalElementen;++i)
{
if(key==m_KeyValueArrPtr[i].getKey())
return m_KeyValueArrPtr[i].getVal();
}
return _T("NOT FOUND");
}
void KeyValueLijst::change(tstring key, tstring newvalue)
{
for(int i=0;i<m_AantalElementen;++i)
{
if(key==m_KeyValueArrPtr[i].getKey())
{
m_KeyValueArrPtr[i].setVal(newvalue);
}
}
}
void KeyValueLijst::erase(tstring key)
{
for(int i=0;i<m_AantalElementen;++i)
{
if(key==m_KeyValueArrPtr[i].getKey())
{
m_KeyValueArrPtr[i].setKey(_T(""));
m_KeyValueArrPtr[i].setVal(_T(""));
}
}
}
void KeyValueLijst::vergrootArray()
{
m_Capaciteit *= 2;
KeyValuePaar* tempArrPtr = new KeyValuePaar[m_Capaciteit];
for(int i=0;i<m_AantalElementen;++i)
{
tempArrPtr[i] = m_KeyValueArrPtr[i];
}
delete[] m_KeyValueArrPtr;
m_KeyValueArrPtr = tempArrPtr;
} |