layout: post

title: 侯捷STL学习(九)

date: 2017-07-21

tag: 侯捷STL

第十九节 容器rb_tree

  • Red-Black tree是自平衡二叉搜索树。

  • rb_tree的封装

  • 清楚传入模板的参数列表;然后构建了一个虚空结点header

  • KeyOfValue表示怎么从value中取出key

  • identity函数(Gnu C独有)就是表示同一个数的意思

  • handle-body,采用OOP的思想,构建G4.9

  • 一个红黑树的大小为4个字节

  • test Rb_tree

#include <set>
#include <functional>
#include <iostream>
namespace jj31
{
void test_Rb_tree()
{
//G2.9 vs. G2.9 :
//rb_tree => _Rb_tree,
//identity<> => _Identity<>
//insert_unique() => _M_insert_unique()
//insert_equal() => _M_insert_equal() cout << "\ntest_Rb_tree().......... \n"; _Rb_tree<int, int, _Identity<int>, less<int>> itree;
cout << itree.empty() << endl; //1
cout << itree.size() << endl; //0 itree._M_insert_unique(3);
itree._M_insert_unique(8);
itree._M_insert_unique(5);
itree._M_insert_unique(9);
itree._M_insert_unique(13);
itree._M_insert_unique(5); //no effect, since using insert_unique().
cout << itree.empty() << endl; //0
cout << itree.size() << endl; //5
cout << itree.count(5) << endl; //1 itree._M_insert_equal(5);
itree._M_insert_equal(5);
cout << itree.size() << endl; //7, since using insert_equal().
cout << itree.count(5) << endl; //3
}
}

容器set,multiset

  • set、multiset元素的value和key合一,value就是key.

  • 容器set实现
  • const_iterator实现set不能改变容器元素的值
  • 使用identity表示set已经知道key和value是相同的

容器map,multimap

  • map/multimap的iterator不能改变key,可以改变value

  • map的结构
  • pair将key和data合成value;将key设置为const,这样通过迭代器就不会改变key的值。

  • select1st实现

  • map容器独特的operator[]操作,可以进行插入操作
  • 直接调用insert快一些

最新文章

  1. boost.python笔记
  2. Android-monkey稳定性测试(多台设备同时进行)
  3. Oracle 备份与恢复介绍
  4. HTML5_用语义化标记重新定义博客
  5. Windows Azure 社区新闻综述(#77 版)
  6. xp每天定时关机命令
  7. ALAssetsLibrary 照片相关 浅析
  8. Python接口自动化测试 HTTP协议
  9. .net Core 微服务框架 surging 使用
  10. UVA - 11732 &quot;strcmp()&quot; Anyone? (trie)
  11. BZOJ3861 : Tree
  12. 使用 git log、git diff 命令时出现 ESC[33 和 ESC[m 乱码的解决办法
  13. Spring Boot log4j多环境日志级别的控制
  14. 使用cglib动态创建javabean
  15. 使用jsonp跨域发送请求
  16. 将JSON字典转换为Model文件
  17. static和final
  18. docker探索-windows10 docker 使用 mysql(二)
  19. PAT——1073. 多选题常见计分法(20)
  20. 附1 consul常用命令+常用选项

热门文章

  1. 出现GC overhead limit exceeded 的解决方案
  2. linux下 stat statfs 获取 文件 磁盘 信息
  3. react列表中,当key改变后发生的事情
  4. POJ2741 Colored Cubes
  5. 运行php的时候出现计算机中丢失 MSVCR110.dll怎么解决
  6. 阿里云分布式缓存OCS与DB之间的数据一致性
  7. 解决:AttributeError: module &#39;requests&#39; has no attribute &#39;get&#39;”
  8. c、rust、golang、swift性能比较
  9. 为mac终端添加tree命令
  10. 13-THREE.JS 点光源