Question: C++ Dynamic Array Help #ifndef ARRAY_H #define ARRAY_H #include using namespace std; template class Array { static const int DEFAULT_CAPACITY = 5; public: using iterator
C++ Dynamic Array Help#ifndef ARRAY_H #define ARRAY_H #include
using namespace std; template class Array { static const int DEFAULT_CAPACITY = 5; public: using iterator = T*; Array(int c) : size(0), capacity(c), items(new T[c]) {} Array() : Array(DEFAULT_CAPACITY) {} Array(const Array &other) : size(other.size), capacity(other.capacity) { items = new T[capacity]; for (int i = 0; i = size) throw runtime_error("Invalid index"); return items[i]; } iterator begin() { return items; } iterator end() { return items + size; } void append(const T &t) { if (size == capacity) increaseCapacity(); items[size++] = t; } void remove() { size--; } int getSize() const { return size; } protected: T *items; int size, capacity; void increaseCapacity() { capacity *= 2; T *itemsNew = new T[capacity]; for (int i = 0; i
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock

#ifndef ARRAY_H #define ARRAY_H #include