博客园 首页 私信博主 显示目录 隐藏目录 管理

STL之stack

 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 ```

 

posted @ 2019-01-27 11:03  Brave_WTZ  阅读(183)  评论(0编辑  收藏  举报