stack push pop empty 栈 入栈 出栈

#include <iostream>
#include <stack>
using namespace std;

int main()
{
    // 创建一个堆栈
    stack<int> s;

    // 向栈中插入元素
    s.push(1);
    s.push(2);
    s.push(3);

    // 将栈中元素依次出栈
    while(!s.empty()){
        cout<<s.top()<<endl;
        s.pop();
    }
    return 0;
}
0

Leave a Reply

Your email address will not be published.