//-------------------------------------------------------------------------------------------------------+ // Copyright (C), 1998-2007, SH Software Co. Ltd. // = FileName : DListStack 模板类 // = Version : ver2.0 // = Author : zjq // = CreateDate : 2002-09-09 // = Description: DListStack 声明 基于双向链表的堆栈 // = Maintainers: // //-------------------------------------------------------------------------------------------------------+ #ifndef _DLISTSTACK_H_ #define _DLISTSTACK_H_ #ifndef _STACK_H_ #include "Stack.h" #endif #ifndef _DUALLIST_H_ #include "DualList.h" #endif template class DListStack : public Stack< T > { public: DListStack(long depth = -1); virtual ~DListStack(); virtual bool Pop(T&t); virtual bool Push(T const&t); virtual void Clear(); virtual bool GetTopData(T&t); virtual long GetDepth(); virtual T& operator[](long i); virtual void GoBack(); virtual void GoAhead(); protected: DualList list; }; template DListStack::DListStack(long depth) : Stack(depth) { } template DListStack::~DListStack() { } template bool DListStack::Push(T const&t) { if(this->IsDepthLimited() && GetDepth() >= this->maxDepth) { return false; } list[list.GetCur()+1] = t; this->oldDepth = GetDepth(); return true; } template bool DListStack::Pop(T&t) { if(this->IsEmpty()) { return false; } t = list.GetCurData(); list.DelCur(); this->oldDepth = GetDepth(); return true; } template bool DListStack::GetTopData(T&t) { if(this->IsEmpty()) { return false; } t = list.GetCurData(); return true; } template void DListStack::Clear() { list.Clear(); this->oldDepth = 0; } template long DListStack::GetDepth() { return list.GetCur() + 1; } template void DListStack::GoBack() { if(this->CanGoBack()) { list.MoveToPre(); } } template void DListStack::GoAhead() { if(this->CanGoAhead()) { list.MoveToNext(); } } template T& DListStack::operator[](long i) { return list[i]; } #endif