码迷,mamicode.com
首页 > 编程语言 > 详细

c++ 顺序容器适配器

时间:2015-03-18 19:47:53      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:

第一次看到stack,以为它是一个和vector同等地位的容器,其实不是

官方解释:stacks are a type of container adaptor, specifically designed to a LIFO context(last-in-first-out), where elements are inserted and extracted only from one end of the container

其实我们手机充电时,连接usb口和插孔的那个大家伙,就是适配器。本质上,适配器是一种机制,能使某种事物的行为看起来像另外一种事物一样。

先贴一个stack应用的例子吧:

技术分享
 1 #include <iostream>
 2 #include <stack>
 3 
 4 using namespace std;
 5 
 6 int main()
 7 {
 8     stack<int> intStack;
 9     for(size_t i = 0; i != 10; i++)
10         intStack.push(i);
11     while(!intStack.empty){
12         int val = intStack.top();  //返回栈顶元素,但不弹出
13         cout << val;  
14         intStack.pop();  //弹出栈顶元素,但不返回该元素值
15     }   
16     cout << endl;
17     return 0;
18 }
seg_container_adaptor_stack

 

c++ 顺序容器适配器

标签:

原文地址:http://www.cnblogs.com/Jshujiao/p/4347818.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!