#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;
}

