#include<cstdlib>
#include<iostream>
#include<cstdio>
#include<stdio.h>
using namespace std;
typedef int ET;
typedef struct
{
int *top;
int *base;
int stacksize;
}stack;
int CreatStack(stack &s,int n)
{
s.base=(int*)malloc(n*sizeof(int));
if(!s.base) exit(0);
s.top=s.base;
s.stacksize=n;
return 1;
}
int empty(stack &s)
{
if(s.base==s.top)
return 1;
else
return 0;
}
void push (stack &s,int e )
{
/* if(s.top-s.base>s.stacksize)
{
s.base=(ET*)malloc((stackmax+stacknum)*sizeof(ET));
if(!s.base)
exit(0);
s.top=s.base+s.stacksize;
s.stacksize+=stacknum;
} */
*s.top++=e;
}
void pop(stack &s)
{
s.top--;
cout<<*s.top<<endl;
}
void choose(stack &s,int n,char c)
{
int x;
if(c=='A')
{
if(empty(s))
cout<<"E"<<endl;
else cout<<*(s.top-1)<<endl;
}
else if(c=='O')
{
if(empty(s))cout<<"E"<<endl;
else pop(s);
}
else if (c=='P')
{
cin>>x;
if(s.top-s.base>=n)
cout<<"F"<<endl;
else push(s,x);
}
}
int main()
{
stack s;
int t,n,m;
char c;
cin>>t;
while(t--)
{
cin>>n>>m;
CreatStack(s,n);
while(m--)
{
cin>>c;
choose(s,n,c);
}
if(t)cout<<endl;
}
return 0;
}
3335 数据结构实验之栈八:栈的基本操作
最新推荐文章于 2018-10-17 12:54:20 发布