namespace lasd { /* ************************************************************************** */ // constructors template StackVec::StackVec(){ size = 4; // default vector is instantiated with 4 cells stackSize = 0; Elements = new Data[size]; } template StackVec::StackVec(const LinearContainer& linear){ // si può richiamare il costruttore della classe Vector Elements = new Data[linear.Size()]; // espandere di un po' forse for(ulong i=0 ; i StackVec::StackVec(const StackVec& stckvec){// si può richiamare il costruttore della classe Vector Elements = new Data[stckvec.size]; // espandere di un po' forse for(ulong i=0 ; i(copyFrom) */ template StackVec::StackVec(StackVec&& toMove) noexcept{ std::swap(Elements, toMove.Elements); std::swap(size, toMove.size); std::swap(stackSize, toMove.stackSize); } template StackVec::~StackVec(){ // Vector destructor will be called automatically // (TEST IT) } template StackVec& StackVec::operator=(const StackVec& copyFrom){ Vector::operator=(copyFrom); // espandere di un po' forse stackSize = copyFrom.Size(); return *this; } template StackVec& StackVec::operator=(StackVec&& moveFrom) noexcept{ Vector::operator=(std::move(moveFrom)); // espandere di un po' forse stackSize = moveFrom.Size(); } template bool StackVec::operator==(const StackVec& toCompare) const noexcept{ if(stackSize == toCompare.Size()){ for(ulong i=0 ; i bool StackVec::operator!=(const StackVec& toCompare) const noexcept{ return !(*this == toCompare); } // Specific member functions (inherited from Stack) template void StackVec::Push(const Data& data){ if(size == stackSize){ Expand(); } Elements[stackSize] = data; ++stackSize; } template void StackVec::Push(Data&& data){ if(size == stackSize){ Expand(); } std::swap(Elements[stackSize], data); ++stackSize; } template Data& StackVec::Top() const{ if(stackSize == 0){ throw std::length_error("Empty Stack! (TOP)"); } return Elements[stackSize-1]; } template void StackVec::Pop(){ if(stackSize==0){ throw std::length_error("Empty Stack! (POP)"); } --stackSize; if(stackSize < (int)(size/4)){ Reduce(); } } template Data StackVec::TopNPop(){ Data data = Top(); Pop(); return data; } template bool StackVec::Empty() const noexcept{ return (stackSize == 0); } template ulong StackVec::Size() const noexcept{ return stackSize; } template void StackVec::Expand(){ Vector::Resize(size * 2); } template void StackVec::Reduce(){ if(size <= 4) return; // we're not going to have vectors with less than 4 cells Vector::Resize((ulong)size/2); } template void StackVec::Clear(){ delete [] Elements; size = 4; stackSize = 0; Elements = new Data[size]; } /* ************************************************************************** */ }