随笔分类 -  STL

摘要:// range heap example#include <iostream>#include <algorithm>#include <vector>using namespace std;int main () { int ia[] = {10,20,30,5,15}; vector<int> ivec(ia,ia+5);make_heap (ivec.begin(),ivec.end()); for (int i = 0; i < (int)ivec.size(); i++) cout<<ivec[i]<<& 阅读全文

posted @ 2012-02-19 09:53 无忧consume 阅读(98) 评论(0) 推荐(0) |

摘要:STL中的容器按存储方式分为两类,一类是按以数组形式存储的容器(如:vector 、deque);另一类是以不连续的节点形式存储的容器(如:list、set、map)。在使用erase方法来删除元素时,需要注意一些问题。在使用 list、set 或 map遍历删除某些元素时可以这样使用:正确使用方法1std::list< int> List;std::list< int>::iterator itList;for( itList = List.begin(); itList != List.end(); ){if(WillDelete(*itList) ){itList 阅读全文

posted @ 2011-12-20 12:38 无忧consume 阅读(427) 评论(0) 推荐(0) |

摘要:对于STL中的map,插入有两种方法:1、map <int,int>a; a[1 ]=1 //此方法初始化a[1],并给a[1]赋值。 a[1]=2 //此方法修改了a[1的值。2 map <int,int>a; a.insert(map<int,int>::value_type(1,1)); //此方法初始化a[1],并给a[1]赋值。 a.insert(map<int,int>::value_type(1,2)); //因为a[1]已经存在,此方法不能初始化a[1],也不能修改a[1]的值。3 特别注意的是,因为[ ]被重载为,如果不存在该k 阅读全文

posted @ 2011-12-20 02:30 无忧consume 阅读(386) 评论(0) 推荐(0) |

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3