//顺序栈#pragmaonceconstint Maxsize =10;template<classT>classSq_Stack{private:
T s[Maxsize];int top;public:Sq_Stack();boolisEmpty();boolisFull();boolPush(T elem);boolPop(T& elem);~Sq_Stack();};
总体实现
//顺序栈#include"Sq_Stack.h"template<classT>Sq_Stack<T>::Sq_Stack(){
top =0;}template<classT>boolSq_Stack<T>::isEmpty(){return top ==0;}template<classT>boolSq_Stack<T>::isFull(){return top == Maxsize;}template<classT>boolSq_Stack<T>::Push(T elem){if(isFull())returnfalse;else{
s[top++]= elem;returntrue;}}template<classT>boolSq_Stack<T>::Pop(T& elem){if(isEmpty())returnfalse;else{
elem = s[--top];returntrue;}}template<classT>
Sq_Stack<T>::~Sq_Stack(){
top =0;}
分块
初始化
template<classT>Sq_Stack<T>::Sq_Stack(){
top =0;}
判空
template<classT>boolSq_Stack<T>::isEmpty(){return top ==0;}
判满
template<classT>boolSq_Stack<T>::isFull(){return top == Maxsize;}