跳到正文

个人记录

手工栈

linzeyu2012约 2 分钟
原文

这是 2026年5月23日 存档的第 1 版,不是当前版本。查看当前版本

文章信息与版本

文章信息

发布
2026年5月23日
收录
2026年5月23日
更新
2026年11月10日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1
C++
template <typename T>
class STACK{
	public:
	    STACK():head(0){}
	    int head;
	    static T data[SSIZE];
	    T top();
	    int size();
	    bool empty();
	    bool pop();
	    bool push(T _data);
	    STACK * operator ->(){return this;}
	    T & operator [](int index){return data[index];}
};
template<typename T> T STACK<T>::data[SSIZE];
template<typename T> T STACK<T>::top(){return data[head];}
template<typename T> int STACK<T>::size(){return head;}
template<typename T> bool STACK<T>::empty(){return size()==0;}
template<typename T> bool STACK<T>::pop(){if(empty()){throw "UNDERFLOW!";return 0;}else{head--;return 1;}}
template<typename T> bool STACK<T>::push(T _data){if(size()==SSIZE){throw "OVERFLOW!";return 0;}else{data[++head]=_data;return 1;}}