1994-08-12 10:52:49 +00:00
|
|
|
#include <stack.h>
|
|
|
|
|
1997-06-03 13:51:20 +00:00
|
|
|
TStack::TStack(int size) : _data(size), _sp(0)
|
1994-08-12 10:52:49 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
void TStack::push(const TObject& o)
|
|
|
|
{
|
1997-06-03 13:51:20 +00:00
|
|
|
_data.add(o, _sp++);
|
1994-08-12 10:52:49 +00:00
|
|
|
}
|
|
|
|
|
1996-08-23 12:58:19 +00:00
|
|
|
void TStack::push(TObject* o)
|
|
|
|
{
|
1997-06-03 13:51:20 +00:00
|
|
|
_data.add(o, _sp++);
|
1996-08-23 12:58:19 +00:00
|
|
|
}
|
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!");
|
1997-06-03 13:51:20 +00:00
|
|
|
return _data[--_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);
|
1997-06-03 13:51:20 +00:00
|
|
|
return _data[_sp-depth-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool TStack::destroy_base()
|
|
|
|
{
|
1998-05-04 08:12:15 +00:00
|
|
|
if (_sp > 0) _sp--;
|
1997-06-03 13:51:20 +00:00
|
|
|
return _data.destroy(0, TRUE);
|
1996-08-23 12:58:19 +00:00
|
|
|
}
|