#pragma once #include template class Array { private: unsigned size, num; //Size and number of elements T* arr; void copy(const Array &other); public: Array(); Array(unsigned S); // Array& operator=(const Array &other); ~Array(); void resize(unsigned toAdd = 0); unsigned gSize()const; unsigned gNum()const; void sNum(unsigned); void push(const T&); void remove(const unsigned id); T& operator[](const unsigned i); T& operator[](const unsigned i)const; Array& operator+=(const Array &other); }; template Array::Array() : size(0), num(0), arr(nullptr) {} template Array::Array(unsigned S) : size(S), num(0) { arr = new T[S]; } template Array& Array::operator=(const Array &other) { copy(other); return *this; } template Array::~Array() { delete[] arr; } template void Array::resize(unsigned toAdd) { toAdd = toAdd ? toAdd : size / 2; T *temp = new T[num]; for (unsigned i = 0; i < num; ++i) temp[i] = arr[i]; delete[] arr; arr = new T[size + toAdd + 1]; for (unsigned i = 0; i < num; ++i) arr[i]=temp[i]; size += toAdd + 1; delete[] temp; } template unsigned Array::gSize()const { return size; } template unsigned Array::gNum()const { return num; } template void Array::sNum(unsigned newNum) { num = newNum; } template void Array::copy(const Array &other) { if (size < other.num) { delete[] arr; arr = new T[other.num]; size = other.num; } for (unsigned i = 0; i < other.num; ++i) arr[i] = other.arr[i]; num = other.num; } template void Array::push(const T& newEl) { if (num >= size) resize(); arr[num] = newEl; ++num; } template void Array::remove(const unsigned id) { --num; arr[id] = arr[num]; } template T& Array::operator[](const unsigned i) { return arr[i]; } template T& Array::operator[](const unsigned i)const { return arr[i]; } template Array& Array::operator+=(const Array &other) { if (size < other.num + num) resize(other.num); unsigned i = 0; for (; i < other.num; ++i) arr[num + i] = other.arr[i]; num += i; return *this; }