#include<iostream> #include<cassert> using namespace std; template<class T, int SIZE = 50> class Stack{ private: T list[SIZE];//数组存放栈的元素 int top;//栈顶位置 public: Stack():top(-1){} void push(const T &item){//将元素压入栈 assert(!isFull()); list[++top] = item; } T pop(){ //将栈顶元素弹出栈 assert(!isEmpty()); return list[top--]; } void clear(){ top = -1; } const T &peek() const{//访问栈顶元素 assert(isEmpty()); return list[top]; } bool isEmpty()const{ return top == -1; } bool isFull()const{ return top == SIZE - 1; } };