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 #include #include 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
> 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 } }