-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTArray.cpp
63 lines (62 loc) · 1.25 KB
/
TArray.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
#include "TArray.h"
TArray::TArray() : max(0), count(0), array(nullptr) {}
TArray::TArray(int _max) {
max = _max;
count = 0;
array = new TNode[max];
}
void TArray::Add(string _key) {
if (count < max || Find(_key) >= 0) {
int answer = 0;
for (int i = 0; i < count; ++i) {
if (array[i].key == _key) {
array[i].value++;
answer = 1;
break;
}
}
if (answer == 0) {
array[count].key = _key;
array[count].value = 1;
count++;
}
}
else cout << "Òàáëèöà çàïîëíåíà." << endl;
}
void TArray::Print() {
cout << endl << "Òàáëèöà:" << endl;
for (int i = 0; i < count; ++i) {
cout << array[i].key << '\t' << array[i].value << endl;
}
cout << endl;
}
bool TArray::IsFull() {
return count == max;
}
bool TArray::IsEmpty() {
return count == 0;
}
int TArray::Find(string s) {
int answer = 0;
int i = 0;
for (; i < count; i++) {
if (array[i].key == s) {
cout << "Êëþ÷ '" << array[i].key << "' íàéäåí â òàáëèöå ñî çíà÷åíèåì " << array[i].value << endl;
answer = 1;
break;
}
}
if (answer == 0) {
cout << "Çàïèñü íå íàéäåíà." << endl;
return -1;
}
else return i;
}
void TArray::Delete(string s) {
int i = Find(s);
if (i >= 0) {
array[i].key = array[count - 1].key;
array[i].value = array[count - 1].value;
count--;
}
}