#include #include using namespace std; class vectorofint { protected: int * data; int capacity; int numitems; public: vectorofint() { capacity = 0; numitems = 0; data = nullptr; } ~vectorofint() { delete [] data; } void resize(int newsize) { if (newsize < capacity) return; int * newdata = new int[newsize]; for (int i = 0; i < numitems; i += 1) newdata[i] = data[i]; delete [] data; data = newdata; capacity = newsize; } void push_back(int value) { if (numitems >= capacity) { int newsize = capacity * 2; if (newsize <= capacity) newsize = capacity + 1; resize(newsize); } data[numitems] = value; numitems += 1; } int back() { assert(numitems > 0); return data[numitems - 1]; } void pop_back() { assert(numitems > 0); numitems -= 1; } int at(int position) { assert(position >= 0); assert(position < numitems); return data[position]; } void assign(int position, int value) { assert(position >= 0); assert(position < numitems); data[position] = value; } int size() { return numitems; } }; int main() { vectorofint V; V.push_back(123); V.push_back(99); V.push_back(7); V.push_back(12'345'678); for (int i = 0; i < V.size(); i += 1) cout << V.at(i) << "\n"; }