题解 | #【模板】循环队列#
【模板】循环队列
https://www.nowcoder.com/practice/0a3a216e50004d8bb5da43ad38bcfcbf
#include <iostream>
using namespace std;
#include<algorithm>
#include <string>
class stack{
private:
int n=0;
int s[100000];
int top=-1;
public:
void push(int x,int n)
{
if(top<n-1)
{
top++;
s[top]=x;
}
else
{
cout<<"full"<<endl;
}
}
void pop()
{
if(top>=0)
{
cout<<s[0]<<endl;
for(int i=0;i<top;i++)
{
s[i]=s[i+1];
}
top--;
}
else cout<<"empty"<<endl;
}
void front()
{
if(top>=0)
{
cout<<s[0]<<endl;
}
else cout<<"empty"<<endl;
}
};
int main() {
// int a, b;
// while (cin >> a >> b) { // 注意 while 处理多个 case
// cout << a + b << endl;
// }
stack s;
int n=0;
int q=0;
cin >>n;
cin>>q;
for(int i=0;i<q;i++)
{
string op;
cin>>op;
if(op=="push")
{
int a=0;
cin>>a;
s.push(a,n);
}
if(op=="pop")
{
s.pop();
}
if(op=="front")
{
s.front();
}
}
return 0;
}
// 64 位输出请用 printf("%lld")



查看5道真题和解析