数据结构--顺序栈--C++实现

#include <iostream>
#define MaxSize 5000
using namespace std;
template <typename T>
class Stack
{
    T data[MaxSize];
    int top;
public:
    void InitStack( )
    {
         top = -1;
    }
    bool StackEmpty( )
    {
        if( top==-1)
            return true;
        else
            return false;
    }
    bool Push(T e)
    {
        if(top==MaxSize-1)
            return false;
        data[++top]=e;
        return true;
    }
    bool Pop( )
    {
        if( top==-1)
            return false;
        return true;
    }
    bool GetTop(T &x)
    {
        if( top==-1) return false;
        x = data[ top];
        return true;
    }
    bool Clear( )
    {
         top = -1;
    }
};
int main()
{
 
}
原文地址:https://www.cnblogs.com/lunatic-talent/p/12798587.html