stack容器

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

int main(){
    
    //初始化
    stack <int> stk;
   
    //入栈
    for(int i=0; i<5; i++){
        stk.push(i);
    }
    cout << "栈的大小: " << stk.size() << endl;

    //top:栈顶,pop:出栈
    while(!stk.empty()){
        cout << stk.top() << endl;
        stk.pop();
    }
    cout << "栈的大小: " << stk.size() << endl;
    return 0;
}
posted @ 2021-12-06 21:12  ayanyuki  阅读(32)  评论(0)    收藏  举报