#pragma once #include "SHStack.h" #include "DualPtrList.h" template class DListStack : public SHStack< 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: DualPtrList list; }; template DListStack::DListStack(long depth) : SHStack(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]; }