campo-sirio/include/stack.cpp
guy 60fa7010c1 expr.cpp Aggiunte nuove funzioni.
stack.cpp      Aggiunto metodo peek.
CV: ----------------------------------------------------------------------


git-svn-id: svn://10.65.10.50/trunk@3429 c028cbd2-c16b-5b4b-a496-9718f37d4682
1996-08-23 12:58:19 +00:00

27 lines
393 B
C++
Executable File

#include <stack.h>
TStack::TStack(int size) : TArray(size), _sp(0)
{}
void TStack::push(const TObject& o)
{
add(o, _sp++);
}
void TStack::push(TObject* o)
{
add(o, _sp++);
}
TObject& TStack::pop()
{
CHECK(count() > 0, "Stack underflow!");
return (*this)[--_sp];
}
TObject& TStack::peek(int depth) const
{
CHECK(depth > _sp, "Stack underflow!");
return (*this)[_sp-depth-1];
}