1994-08-12 10:52:49 +00:00
|
|
|
#include <stack.h>
|
|
|
|
|
|
|
|
TStack::TStack(int size) : TArray(size), _sp(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
void TStack::push(const TObject& o)
|
|
|
|
{
|
1994-12-29 14:51:43 +00:00
|
|
|
add(o, _sp++);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
1996-08-23 12:58:19 +00:00
|
|
|
void TStack::push(TObject* o)
|
|
|
|
{
|
|
|
|
add(o, _sp++);
|
|
|
|
}
|
1995-06-22 09:30:05 +00:00
|
|
|
|
1994-08-12 10:52:49 +00:00
|
|
|
TObject& TStack::pop()
|
|
|
|
{
|
1994-12-29 14:51:43 +00:00
|
|
|
CHECK(count() > 0, "Stack underflow!");
|
|
|
|
return (*this)[--_sp];
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
1996-08-23 12:58:19 +00:00
|
|
|
|
|
|
|
TObject& TStack::peek(int depth) const
|
|
|
|
{
|
|
|
|
CHECK(depth > _sp, "Stack underflow!");
|
|
|
|
return (*this)[_sp-depth-1];
|
|
|
|
}
|