STL Stack

View Code
 1 #include <iostream>
2 #include<stack>
3 #include<vector>
4 #include<list>
5
6 using namespace std;
7
8
9 int main()
10
11 {
12
13 stack<int,deque<int>> a;
14 stack<int,vector<int>> b;
15 stack<int,list<int>> c;
16 stack<int> d;
17
18 d.push(25);
19 d.push(10);
20 d.push(1);
21 d.push(5);
22
23 cout << "现在栈里有: "<< d.size() << "个数据。" << endl;
24
25 //while(d.size()!=0)
26 while(d.empty()==false) //两种写法都可以
27 {
28
29 int x =d.top();//pop是删除数据不返回 显示嘴上一个得用top
30 cout << x << endl;
31 d.pop();
32
33 }
34
35 cout << "现在栈里有: "<< d.size() << "个数据。" << endl;
36
37 /*int y =d.top();//pop是删除数据不返回 显示嘴上一个得用top
38 d.pop();
39 cout << y << endl;
40
41 cout << "现在栈里有: "<< d.size() << "个数据。" << endl;
42
43 */
44 return 0;
45
46
47
48 }
posted @ 2012-03-27 23:30  uniquews  阅读(158)  评论(0编辑  收藏  举报