后进先出,栈中没有元素时令top=-1
清空
void clear(){ TOP=-1; }
获取栈内元素个数
int size(){ return TOP+1; }
判空
bool empty(){ if(TOP==-1){ return true; } else{ return false; } }
进栈
void push(int x){ st[++TOP]=x; }
出栈
void pop(int x){ TOP--; }
取栈顶元素
int top(){ return st[TOP]; }
对栈的清空
while(!st.empty()){ st.pop(); }
原文:https://www.cnblogs.com/ak918xp/p/13548293.html