//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, Beijing Tangent Software Co. Ltd. // = FileName : TSqStack 模板类 // = Version : ver2.0 // = Author : wlw // = CreateDate : 2002-09-09 // = Description: TSqStack 声明 基于动态数组的堆栈 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #ifndef _TSQSTACK_H_ #define _TSQSTACK_H_ #ifndef _TSTACK_H_ #include "TStack.h" #endif #ifndef _TSQTABLE_H_ #include "TSqTable.h" #endif template class TSqStack: public TStack { public: TSqStack(long autoAllocUnit = 100,long depth = -1); virtual ~TSqStack(); virtual void Clear(); virtual void GoBack(); virtual void GoAhead(); virtual bool Pop(T&t); virtual bool Push(T const&t); virtual bool GetTopData(T&t); virtual long GetDepth(); virtual T& operator[](long i); protected: TSqTable table; }; template TSqStack::~TSqStack() { } template virtual T& TSqStack::operator[](long i) { return table[i]; } template TSqStack::TSqStack(long autoAllocUnit,long depth) :TStack(depth),table(autoAllocUnit,autoAllocUnit) { } template bool TSqStack::Push(T const&t) { if(this->IsDepthLimited() && this->GetDepth() >= this->maxDepth) { return false; } table[table.GetCur()+1] = t; this->oldDepth = GetDepth(); return true; } template bool TSqStack::Pop(T&t) { if(this->IsEmpty()) { return false; } t = table.GetCurData(); table.MoveToPre(); return true; } template bool TSqStack::GetTopData(T&t) { if(this->IsEmpty()) { return false; } t = table.GetCurData(); return true; } template void TSqStack::Clear() { table.Clear(); this->oldDepth = 0; } template long TSqStack::GetDepth() { return table.GetCur()+1; } template void TSqStack::GoBack() { if(this->CanGoBack()) { table.MoveToPre(); } } template void TSqStack::GoAhead() { if(this->CanGoAhead()) { table.MoveToNext(); } } #endif