#ifndef BAG_H #define BAG_H template class Bag { private: Item * v; int n; int tam; void resize(int tam); public: Bag(); ~Bag(); void insere(Item item); bool bagVazia(); int nElem(); Item at(int i); }; template Bag::Bag(): n(0), tam(1), v(new Item[1]) {}; template Bag::~Bag() { if (v != nullptr) delete [] v; } template void Bag::insere (Item item) { if (n == tam) resize(2 * tam); v[n] = item; n++; } template bool Bag::bagVazia () { return (n == 0); } template int Bag::nElem() { return (n); } template Item Bag::at(int i) { if (i >= 0 && i < n) return (v[i]); } template void Bag::resize(int t) { Item * novoV = new Item[t]; for (int i = 0; i < n; i++) novoV[i] = v[i]; delete [] v; v = novoV; tam = t; } #endif