/*************************************************************************** stack.cpp - description ------------------- begin : mar mag 6 2008 copyright : (C) 2008 by Gabriele Di Stefano email : gabriele@ing.univaq.it ***************************************************************************/ /*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/ #include "stack.h" #include Stack::Stack(){ } int Stack::size() const{ return elementi.size(); } void Stack::push(int x){ elementi.push_back(x); } void Stack::pop() throw(Eccezione){ if (elementi.size()==0) throw Eccezione("Stack vuoto, pop() non eseguibile"); elementi.pop_back(); } int Stack::top() const{ if (elementi.size()==0) throw Eccezione("Stack vuoto, top() non eseguibile"); return elementi.back(); }