#include #include "WordArrayT.h" using namespace std; WordArrayT::WordArrayT() { } WordArrayT::~WordArrayT() { delete[] data; } WordArrayT::WordArrayT(const WordArrayT & other){ capacity = other.capacity; size = other.size; data = new DataT[capacity]; for(size_t i =0; i < size; ++i) { data[i] = other.data[i]; } } WordArrayT & WordArrayT::operator = (const WordArrayT & other){ if (&other != this) { delete[] data; capacity = other.capacity; size = other.size; data = new DataT[capacity]; for(size_t i =0; i < size; ++i) { data[i] = other.data[i]; } } return *this; } bool WordArrayT::PushBack(DataT newWord){ bool good = false; if (size >= capacity) { DataT * temp; if (capacity == 0) { capacity = 10; } else { capacity *= 2; } temp = new DataT[capacity]; for(size_t i = 0; i < size; ++i) { temp[i] = data[i]; } if (data != nullptr) { delete[] data; } data = temp; } data[size] = newWord; ++size; good = true; return good; } DataT & WordArrayT::operator[](size_t index){ return data[index]; } const DataT & WordArrayT::operator[](size_t index) const{ return data[index]; } DataT & WordArrayT::at(size_t index){ if (index < size) { return data[index]; } cerr << "Error: Out of bounds index " << index << endl; return data[0]; } const DataT & WordArrayT::at(size_t index) const{ if (index < size) { return data[index]; } cerr << "Error: Out of bounds index " << index << endl; return data[0]; } size_t WordArrayT::Capacity() const{ return capacity; } size_t WordArrayT::Size() const{ return size; }