栈
2023-10-15 10:34:46
发布于:北京
#include<bits/stdc++.h>
using namespace std;
int st[100],TOP=0;
//入栈
void push(int x){
TOP++;
st[TOP]=x;
}
//出栈
void pop(){
TOP--;
}
//取栈顶元素
int top(){
return st[TOP];
}
//判断栈是否为空
bool empty(){
return TOP0;
//if(TOP0) return true;
//else return false;
}
//清空栈
void clear(){
TOP=0;
}
//栈的大小
int size(){
return TOP;
}
int main(){
for(int i=1;i<=5;i++){//将1~5入栈
push(i);
}
cout<<top()<<endl;
while(!empty()){
cout<<top()<<" ";
pop();
}
return 0;
}
这里空空如也
有帮助,赞一个