# 13896 - Darray stack for postfix calculation (4/10) >author: Utin ###### tags: `class` --- ## Brief See the code below ## Solution 0 ```cpp= #include <iostream> #include <string> #include "function.h" using namespace std; Darray::~Darray() { delete[] data; } int& Darray::operator[](int i) { return data[i]; } void Darray::pushback(int x) { if (size >= capacity) resize(); data[size] = x; size++; } void Darray::popback(void) { if (size > 0) size--; } void Darray::clear(void) { size = 0; } int Darray::length(void) { return size; } int Darray::back(void) { return data[size - 1]; } void Darray::resize(void) { capacity *= 2; int* tmp = new int[capacity]; for (int i = 0; i < size; i++) { tmp[i] = data[i]; } delete[] data; data = tmp; } Darray_stack::Darray_stack() : arr() {} void Darray_stack::operator << (const int& x) { arr.pushback(x); } void Darray_stack::operator >> (int& x) { x = arr.back(); arr.popback(); } // Utin ``` ## Reference