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()
|
|
|
|
{
|
1996-08-30 14:30:08 +00:00
|
|
|
CHECK(_sp > 0, "Stack underflow!");
|
1994-12-29 14:51:43 +00:00
|
|
|
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
|
|
|
|
{
|
1996-08-30 14:30:08 +00:00
|
|
|
CHECKD(depth >= 0 && depth < _sp, "Stack depth error: ", depth);
|
1996-08-23 12:58:19 +00:00
|
|
|
return (*this)[_sp-depth-1];
|
|
|
|
}
|