特殊线性表——栈 const int StackSize=100; template class SeqStack { public: SeqStack(){top=-1;}; ~SeqStack(); void Push(T x); T Pop(); T GetTop(){if(top!=-1)return data[top];} bool Empty(){ if(top==-1)return 1;else return 0;} private: T data[StackSize]; int top; }
两栈共享空间 const int StackSize=100; template class BothStack { public: BothStack(){top1=-1;top2=StackSize;} ~BothStack(); void Push(int i,T x); T Pop(int i); bool Empty(int i); private: T data[StackSize]; int top1,top2; }; 特殊线性表——队列 (类的声明) const int QueueSize=100; template class CirQueue { pblic: CirQueue(){front=rear=QueueSize-1;} ~CirQueue(); void EnQueue(T x); T DeQueue(); T GetQueue(); bool Empty(){return(front==rear?1:0);} private: T data[QueueSize]; int front,rear; };