stack容器 Posted on 2020-04-22 | In STL Words count in article: 215 | Reading time ≈ 1 stack容器 1234567891011121314151617181920212223242526272829303132333435363738394041//// Created by Jason on 2020/3/29.///*3.4.3.1 stack构造函数 stack<T>stkT∥stack采用模板类实现,stack对象的默认构造形式 stack( const stack&stk)://拷贝构造函数3.4.3.2 stack赋值操作 stack operator( const stack &stk);/重载等号操作符3.4.3.3 stack数据存取操作。 push(elem)//栈顶添加元素 pop();//从栈顶移除第一个元素 top();/返回栈顶元素3.4.3.4 stack大小操作 empty();//判断堆栈是否为空 size();//返回堆栈的大小 * */#include<bits/stdc++.h>using namespace std;void test01(){ stack<int>s; //入栈 s.push(10); s.push(20); s.push( 30); s.push(40); while (!s.empty()) { //输出栈顶元素 cout<<s.top()<<endl; s.pop(); } cout<<"栈的大小"<<s.size()<<endl;}int main(){ test01(); system("pause"); return 0;} -------------本文结束,感谢您的阅读------------- Post author: Jason Post link: https://jasonxqh.github.io/2020/04/22/stack%E5%AE%B9%E5%99%A8/ Copyright Notice: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.