blob: 23d965901498deadca330b9ddc6c8a62630acb96 (
plain) (
blame)
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
|
#include "Administrator.h"
#include <iostream>
void Administrator::resize() {
allocated *= 2;
int* bigger = new int[allocated];
for (int i = 0; i < size; i++) {
bigger[i] = arr[i];
}
delete[] arr;
arr = bigger;
}
void Administrator::free() {
delete[] arr;
}
void Administrator::copyFrom(const Administrator& other) {
this->arr = new int[other.allocated];
for (int i = 0; i < other.size; i++) {
this->arr[i] = other.arr[i];
}
}
Administrator::Administrator() : Moderator() {
arr = nullptr;
size = allocated = 0;
}
Administrator::~Administrator() {
free();
}
Administrator::Administrator(const Administrator& other) : Moderator(other) {
copyFrom(other);
}
Administrator& Administrator::operator=(const Administrator& other) {
if (this != &other) {
Moderator::operator=(other);
free();
copyFrom(other);
}
return *this;
}
Administrator::Administrator(Administrator&& other) : Moderator(other) {
this->arr = other.arr;
other.arr = nullptr;
this->size = other.size;
this->allocated = other.allocated;
}
Administrator& Administrator::operator=(Administrator&& other) {
if (this != &other) {
free();
Moderator::operator=(std::move(other));
this->arr = other.arr;
other.arr = nullptr;
this->size = other.size;
this->allocated = other.allocated;
}
return *this;
}
void Administrator::AddID(int value) {
if (allocated <= size) {
resize();
}
arr[size++] = value;
}
void Administrator::RemoveID(int value) {
int i;
for (i = 0; i < size; i++) {
if (arr[i] == value) {
break;
}
}
for (; i < size - 1; i++) {
arr[i] = arr[i+1];
}
size--;
}
|