首页 > 其他 > 详细

STL之stack

时间:2019-01-27 12:17:03      阅读:159      评论:0      收藏:0      [点我收藏+]
 1 ```
 2 #include<iostream>
 3 #include<algorithm>
 4 #include<stack>
 5 #include<cstring>
 6 #include<cstdlib>
 7 using namespace std;
 8 
 9 void test01(){
10     //初始化
11     stack<int> s1;
12     stack<int> s2(s1);
13 
14     //stack操作
15     s1.push(10);
16     s1.push(20);
17     s1.push(30);
18     s1.push(100);
19     cout<<"栈顶元素:"<<s1.top()<<endl;
20     s1.pop();//删除栈顶元素
21 
22     //打印栈容器数据
23     while(!s1.empty()){
24         cout<<s1.top()<<" ";
25         s1.pop();
26     }
27     cout<<endl;
28     cout<<"size:"<<s1.size()<<endl;
29 
30 }
31 
32 int main()
33 {
34     test01();
35 
36     return 0;
37 }
38 
39 ```

 

STL之stack

原文:https://www.cnblogs.com/Bravewtz/p/10325816.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!