数据结构--顺序栈--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()
{
 
}

 

posted @ 2019-11-17 22:40  风骨散人  阅读(129)  评论(0编辑  收藏  举报