Cpp容器库和相关操作总结
顺序容器
vector
member functions:
constructor、destructor、operator=、assign、get_allocator
Element access
- at
- operator
- front
- back
- data
Iterators
- begin/cbegin
- end/cend
- rbegin/c rbegin
- rend/c rend
Capacity
- empty
- size
- max_size
- reserve
- capacity
- shrink_to_fit
Modifiers
- clear
- insert
- emplace:相较于insert,不需要产生一个临时变量。
- erase
- push_back
- resize
- swap
non-member functions
- operator==
- swap
- erase
deque
双端队列
list
双向链表
forward_list
单向链表
array
array 容器的大小是固定的,无法动态的扩展或收缩,这也就意味着,在使用该容器的过程无法借由增加或移除元素而改变其大小,它只允许访问或者替换存储的元素。
string
Iterators
- begin/cbegin
- end/cend
- rbegin/c rbegin
- rend/c rend
Capacity
- empty
- size
- length
- max_size
- reserve
- capacity
- clear
- shrink_to_fit
Element access
- at
- operator
- front
- back
Modifiers
- +=
- append
- push_back
- assign
- insert
- erase
- replace
- swap
- pop_back
关联容器
set
Iterators
- begin / cbegin
- end / cend
- rbegin / c rbegin
- rend / c rend
Capacity
- empty
- size
- max_size
Modifiers
- clear
- insert
- emplace
- emplace_hint
- erase
- swap
- extract
- merge
Lookup
- count
- find
- contains
- equal_range
- lower_bound
- upper_bound
map
Element accress
- at
- operator
Iterators
- begin / cbegin
- end / cend
- rbegin / c rbegin
- rend / c rend
Capacity
- empty
- size
- max_size
Modifiers
- clear
- insert
- insert_or_assign
- emplace
- emplace_hint
- try_emplace
- erase
- swap
- extract
- merge
Lookup
- count
- find
- contains
- equal_range
- lower_bound
- upper_bound
multimap
允许多个多个元素具有相同的关键词。主要应用有:例如词典中一个单词可以有多个意思。
multiset
unordered_map
无序容器不使用比较运算符来组织元素,而是使用一个哈希函数和关键字类型的==运算符。在关键字类型的元素没有明显的序关系的情况下,无序容器非常有用。某些应用中维护元素序的代价非常高昂,此时无序容器也很有用。
unordered_set
unordered_multimap
unordered_multimet
容器适配器
priority_queue
Element access
- top
Capacity
- empty
- size
Modifiers
- push
- emplace
- pop
- swap
stack
与priority_queue相同。
queue
Element access
- front
- back
Capacity
- empty
- size
Modifiers
- push
- emplace
- pop
- swap
list
最后修改于 2021-12-16