aboutsummaryrefslogtreecommitdiff
path: root/week13/Exercise1/IndexArray.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'week13/Exercise1/IndexArray.cpp')
-rw-r--r--week13/Exercise1/IndexArray.cpp51
1 files changed, 51 insertions, 0 deletions
diff --git a/week13/Exercise1/IndexArray.cpp b/week13/Exercise1/IndexArray.cpp
new file mode 100644
index 0000000..ed7a212
--- /dev/null
+++ b/week13/Exercise1/IndexArray.cpp
@@ -0,0 +1,51 @@
+#include "IndexArray.h"
+#include <cstring>
+
+void IndexArray::free() {
+ delete[] indecies;
+}
+
+void IndexArray::copyFrom(const IndexArray& other) {
+ this->size = other.size;
+ this->indecies = new int[size];
+ for (int i = 0; i < size; i++) {
+ this->indecies[i] = other.indecies[i];
+ }
+}
+
+IndexArray::IndexArray() {
+ this->indecies = nullptr;
+ this->size = 0;
+}
+
+IndexArray::~IndexArray() {
+ free();
+}
+
+IndexArray::IndexArray(const IndexArray& other) {
+ copyFrom(other);
+}
+
+IndexArray& IndexArray::operator=(const IndexArray& other) {
+ if (this != &other) {
+ free();
+ copyFrom(other);
+ }
+ return *this;
+}
+
+IndexArray::IndexArray(IndexArray&& other) {
+ this->indecies = other.indecies;
+ other.indecies = nullptr;
+}
+
+IndexArray& IndexArray::operator=(IndexArray&& other) {
+ if (this != &other) {
+ free();
+
+ this->indecies = other.indecies;
+ other.indecies = nullptr;
+ }
+ return *this;
+}
+