From 9c11fababb9b6b194e646fbeb62d141aacf74c43 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 25 May 2024 16:08:17 +0300 Subject: [w13] Added solutions --- week13/Exercise1/IndexArray.cpp | 51 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 week13/Exercise1/IndexArray.cpp (limited to 'week13/Exercise1/IndexArray.cpp') 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 + +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; +} + -- cgit v1.2.3