#include < iostream >
using namespace std;
#define stack_size 10
int stack[stack_size];
int top = 0;
void Init_Stack() //初始化顺序栈
{
top = -1;
}
void push_stack(int x)
{
if (top == stack_size)
cout << "栈满!" << endl;
else
{
top++;
stack[top] = x;
}
}
void pop_stack()
{
if (top == -1)
cout << "栈下溢!" << endl;
else
{
top--;
}
}
int main()
{
Init_Stack(); //初始化顺序栈
cout << "请输入你想入站的元素个数:"; //顺序栈的建立
int n;
cin >> n;
cout << "入站的元素依次为:" << endl;
for (int i = 0; i < n; i++)
{
int x;
cin >> x;
push_stack(x);
}
cout << "请输入你想出站的元素个数:"; //顺序栈的出栈操作
int n1;
cin >> n1;
cout << "出站的元素依次为:" << endl;
for (int i = 0; i < n1; i++)
{
pop_stack();
cout << stack[top + 1] << " ";
}
cout << endl;
return 0;
}