hyhyhy
2024-08-05 15:24:52
发布于:广东
#include<bits/stdc++.h>
using namespace std;
int a[1005];
int TOP=0;
void push(int x){
a[++TOP]=x;
}
void pop(){
TOP--;
}
bool empty(){
return TOP==0;
}
int size(){
return TOP-0;
}
int main(){
int n;
cin>>n;
while(n--){
string s;
cin>>s;
if(s=="push"){
int x;
cin>>x;
push(x);
for(int i=1;i<=size();i++){
cout<<a[i]<<" ";
}
cout<<endl;
}else{
//出栈
if(size()==0) cout<<"pop fail"<<endl;
else pop();
}
}
return 0;
}
这里空空如也
有帮助,赞一个