• 声明和实现顺序栈模板类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(){
    
    }
    
    
  • 相关阅读:
    Alpha冲刺(4/6)
    Alpha冲刺(3/6)
    Alpha冲刺(2/6)
    Alpha冲刺(1/6)
    团队Git现场编程实战
    团队项目-需求分析报告
    团队项目-选题报告
    第二次结对编程作业
    第一次团队展示
    第一次结对编程作业
  • 原文地址:https://www.cnblogs.com/ygbrsf/p/12519597.html
Copyright © 2020-2023  润新知