声明和实现顺序栈模板类SeqList

20191111第一次更新

/**
 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.yx.telstudy.xyz
 *    created:
 */
#include <cstdio>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include <cstring>
#include <string>
#include <cmath>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;

using namespace std;

const int StackSize = 10;
template<class DataType>
class SeqStack{
public :
    SeqStack(){top = -1;}
    ~SeqStack(){};
    void Push(DataType x);
    DataType Pop();
    DataType GetTop(){if (top!=-1){return data[top];}}
    int Empty(){return top == -1 ?  1:  0;}
private:
    DataType data[StackSize];
    int top;
};

//出栈
template<class DataType>
DataType SeqStack<DataType>::Pop(){
    if (top == -1) throw "下溢";
    return data[top--];
}

//入栈
template<class DataType>
void SeqStack<DataType>::Push(DataType x){
    if (top == StackSize-1){throw "上溢";}
    data[++top] = x;
}

int main(){

}

原文地址:https://www.cnblogs.com/ygbrsf/p/12519597.html