STL标准函数库 stack容器

1.stack的功能:
先进后出

#include<bits/stdc++.h>
using namespace std;
int main()
{
    stack<int> S;
    S.push(3);
    S.push(7);
    S.push(1);
    cout << S.size() << " ";

    cout << S.top() << " ";    //返回栈顶元素
    S.pop();                   //从栈取出并删除元素

    cout << S.top() << " ";
    S.push(5);                 //向栈内添加元素

    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37360631/article/details/81430737