文档详情

C++ STL之set容器使用方法C++ STL之set容器使用方法.doc

发布:2017-12-13约1.3万字共10页下载文档
文本预览下载声明
C++ STL之Set容器的用法 1 set中的元素类型 1 2 set中构造相关函数 2 3 set中的迭代器 3 4 set中的容量相关函数 3 5 set中元素修改函数 3 5.1 insert 函数 3 5.2 erase 函数 4 5.3 clear 函数 5 5.4 swap 函数 5 5.5 emplace 函数 5 5.6 emplace_hint 函数 5 6 set 中的比较函数体 6 6.1 key_com 函数 6 6.2 value_com 函数 6 7 set的其他操作函数 7 7.1 find 函数 7 7.2 count 函数 8 7.3 lower_bound 函数 8 7.4 upper_bound 函数 8 7.5 equal_range 函数 9 7.6 get_allocator 函数 10 Set容器是一个关联容器,容器中的元素互不相同,并且容器中的元素按照键值大小进行排序。每当插入或者删除一个元素,容器都会重新排序。Set容器有两大特点,一个是元素排序,另一个就是查询速度快(当然没有vector快)。Set获取元素时通过键值,关联容器都这样。Set是通过二元查找树实现的,再具体点就是红黑树。 1 set中的元素类型 member type definition notes key_type The first template parameter (T) value_type The first template parameter (T) key_compare The second template parameter (Compare) defaults to:?lesskey_type value_compare The second template parameter (Compare) defaults to:?lessvalue_type allocator_type The third template parameter (Alloc) defaults to:allocatorvalue_type reference allocator_type::reference for the default?allocator:value_type const_reference allocator_type::const_reference for the default?allocator:?const value_type pointer allocator_type::pointer for the default?allocator:value_type* const_pointer allocator_type::const_pointer for the default?allocator:?const value_type* iterator a?bidirectional iterator?to?value_type convertible to?const_iterator const_iterator a?bidirectional iterator?to?const value_type reverse_iterator reverse_iteratoriterator const_reverse_iterator reverse_iteratorconst_iterator difference_type a signed integral type, identical to:iterator_traitsiterator::difference_type usually the same as?ptrdiff_t size_type an unsigned integral type that can represent any non-negative value of?difference_type usually the same as?size_t 关于这个无需多言,切记set中的iterator是指向const 元素。 set中构造相关函数 empty (1) explicit set (const key_compare comp = key_compare(), const allocator_type alloc = allocator_type()); explicit set (const allocator_type alloc); range (2) template class InputIterator set (Inpu
显示全部
相似文档