#include<iostream>
#include<cstdlib>
using namespace std;
typedef struct
{
int data[100];
int top;
}Stack;
void Init(Stack *&s)
{
s=(Stack *)malloc(sizeof(Stack));
s->top=-1;
}
bool Push(Stack *&s,int e)
{
if(s->top==99) return false;
s->top++;
s->data[s->top]=e;
return true;
}
bool Out(Stack *&s,int e)
{
if(s->top==-1) return false;
e=s->data[s->top];
s->top--;
return true;
}
bool is(Stack *&s)
{
if(s->top==-1) return true;
else return false;
}
int Get(Stack *&s,int e)
{
e=s->data[s->top];
return e;
}
int main()
{
Stack *s;
Init(s);
int i,n,m; //入栈元素个数
int tmp,top;
int a[100];
cin>>n;
for(i=0;i<n;i++)
{
cin>>a[i];
Push(s,a[i]);
}
cin>>m; //出栈操作次数
for(i=0;i<m;i++)
{
Out(s,tmp);
}
if(is(s)) cout<<-1;
else
cout<<Get(s,top);
return 0;
}
SWUST数据结构--顺序栈基本操作的实现
最新推荐文章于 2022-07-21 22:15:26 发布
