随笔分类 -  C++之STL

stl之map 排序
摘要:排序问题,STL中默认是采用小于号来排序的,因为设置int等类型做key,它本身支持小于号运算,在一些特殊情况,比如关键字是一个结构体,涉及到排序就会出现问题,因为它没有小于号操作,insert等函数在编译的时候过不去,下面给出两个方法解决这个问题: 第一种:小于号重载,程序举例 第二种:仿函数的应 阅读全文

posted @ 2015-12-17 10:53 阳台 阅读(2924) 评论(2) 推荐(0) 编辑

STL之map
摘要:map中的key必须重载 " 2 #include 3 #include 4 5 using namespace std; 6 7 int main() 8 { 9 std::map* > test_map;10 std::map map_01 ; 11 fo... 阅读全文

posted @ 2015-07-20 10:39 阳台 阅读(216) 评论(0) 推荐(0) 编辑

map的erase()释放内存
摘要:STL中的map调用erase(it),当value值为指针时,释放内存: 1 #include 2 #include 3 #include 4 5 using namespace std; 6 struct value{ 7 int i; 8 std::string te... 阅读全文

posted @ 2015-07-09 11:08 阳台 阅读(1816) 评论(0) 推荐(0) 编辑

STL之priority_queue为复合结构排序
摘要:priority_queue为复合结构排序: 1 #include 2 #include 3 4 using namespace std; 5 struct Node{ 6 int x; 7 string y; 8 Node( int a= 0, string ... 阅读全文

posted @ 2015-07-08 18:57 阳台 阅读(313) 评论(0) 推荐(0) 编辑

STL之使用vector排序
摘要:应用场景: 在内存中维持一个有序的vector: 1 // VectorSort.cpp : Defines the entry point for the console application. 2 3 #include 4 #include 5 #include 6 7 //先自定... 阅读全文

posted @ 2015-07-08 18:53 阳台 阅读(1009) 评论(0) 推荐(0) 编辑

STL之string插入
摘要:1 #include 2 #include 3 4 using namespace std; 5 int main() 6 { 7 string s("hello"); 8 string s2("abcdef"); 9 10 string::ite... 阅读全文

posted @ 2015-06-22 21:25 阳台 阅读(999) 评论(0) 推荐(0) 编辑

STL之string
摘要:string构造函数,很多重载函数; 1 #include 2 #include 3 4 using namespace std; 5 int main() 6 { 7 string s1; 8 cout << s1 << endl; 9 10 string s2(5... 阅读全文

posted @ 2015-06-22 09:36 阳台 阅读(179) 评论(0) 推荐(0) 编辑

STL之如何选择顺序容器
摘要:一、顺序容器的分类 顺序容器:vector向量、list链表、deque双端队列; 优先级最高的是vector向量,它的速度比较快,优点最多; 在程序设计中,容器可以切换; 1 #include 2 #include 3 #include 4 #include 5 6 using n... 阅读全文

posted @ 2015-06-21 23:15 阳台 阅读(310) 评论(0) 推荐(0) 编辑

STL之vector详解
摘要:一、vector容器的自增长 首先,我们知道vector容器是由数组做出来的;它具备了数组的优缺点.数组的优点: 操作数据,读取速度很快,因为有下标;数组的缺点: 分配之后不能在改变大小; 1 #include 2 #include 3 4 using namespace std; 5 ... 阅读全文

posted @ 2015-06-21 22:55 阳台 阅读(340) 评论(0) 推荐(0) 编辑

顺序容器
摘要:一、顺序容器的相关操作:示例: 1 #include 2 #include 3 #include 4 #include 5 6 using namespace std; 7 int main() 8 { 9 vector a;10 list b;11 deque... 阅读全文

posted @ 2015-05-31 23:30 阳台 阅读(180) 评论(0) 推荐(0) 编辑

STL之迭代器
摘要:一、概述:(容器、算法、迭代器) 1、每一种容器都有自己的迭代器; 2、所有的迭代器接口都是一样的; 3、在整个标准库中,经常使用形参为一对迭代器的构造函数; 4、常用的迭代器操作: *iter、 ++iter、 --iter、 iter1 == iter2, iter1 != ite... 阅读全文

posted @ 2015-05-26 23:20 阳台 阅读(215) 评论(0) 推荐(0) 编辑

STL之顺序容器
摘要:顺序容器: vector:数组 list:链表 deque:双端数组顺序容器适配器: stack:堆栈 queue:队列 priority_queue:优先级队列 deque是一个动态数组 deque与vector非常类似; deque可以在在数组开头和末尾插入和删除数据; 1 #... 阅读全文

posted @ 2015-05-18 23:52 阳台 阅读(265) 评论(0) 推荐(0) 编辑

STL之优先级队列priority_queue
摘要:摘要: priority_queue,自适应容器(即容器适配器):不能由list来组建; 最大值优先级队列(最大值始终在对首,push进去时候) 最小值优先级队列; 优先级队列适配器 STL priority_queue priority_queue > pg; priority_que... 阅读全文

posted @ 2015-05-17 23:07 阳台 阅读(298) 评论(0) 推荐(0) 编辑

ST
摘要:FG 阅读全文

posted @ 2015-05-17 23:07 阳台 阅读(124) 评论(0) 推荐(0) 编辑

STL之Queue(Q)
摘要:STL的Queue(数据结构中的队列): 特点:FIFO 先进先出; 自适应容器(即容器适配器) 栈适配器STL queue STL中实现的Queue: 用list来实现queue; queue > q; 用deque来实现queue; queue > q; ... 阅读全文

posted @ 2015-05-17 21:43 阳台 阅读(523) 评论(0) 推荐(0) 编辑

STL之stack
摘要:一、stack(栈) 栈:LIFO 后进先出; 首先要指出的是,stack并非和STL的其他类模板是独立的容器,stack是自适应容器(容器适配器) stack> s; stack> s; stack> s; STL中实现的stack方法: s,empty(); s... 阅读全文

posted @ 2015-05-16 00:43 阳台 阅读(278) 评论(0) 推荐(0) 编辑

STL之顺序容器
摘要:一、顺序容量STL list类(双向链表) list是一个模板类,可以在list头部、尾部、中间任意部位很方便地插入元素,这就区别于STL的其他模板类; vector向量只能在尾部插入数据; deque可以在头部和尾部拆入; 标准模板类中实现了对list中元素的反转和排序方法; 1 #inc... 阅读全文

posted @ 2015-05-15 23:58 阳台 阅读(268) 评论(0) 推荐(0) 编辑

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示