当前位置:网站首页>C + + STL container

C + + STL container

2020-11-10 08:45:50 D3qbz0a

Containers Underlying data structure Time complexity There is disorder It can't be repeated other
array Array Read at random O(1) disorder repeatable Support random access
vector Array Read at random 、 Tail insertion 、 Tail delete O(1), Head insertion 、 Head delete O(n) disorder repeatable Support random access
deque deque Insert head and tail 、 Delete the beginning and the end O(1) disorder repeatable A central controller + Multiple buffers , Support the rapid addition and deletion of , Support random access
forward_list One way linked list Insert 、 Delete O(1) disorder repeatable Random access is not supported
list Double linked list Insert 、 Delete O(1) disorder repeatable Random access is not supported
stack deque / list Insert at the top 、 Delete at the top O(1) disorder repeatable deque or list Close the head end opening , no need vector The reason should be that the capacity is limited , Expansion takes time
queue deque / list Tail insertion 、 Head delete O(1) disorder repeatable deque or list Close the head end opening , no need vector The reason should be that the capacity is limited , Expansion takes time
priority_queue vector + max-heap Insert 、 Delete O(log2n) Orderly repeatable vector Containers +heap Handling rules
set Red and black trees Insert 、 Delete 、 lookup O(log2n) Orderly Do not repeat
multiset Red and black trees Insert 、 Delete 、 lookup O(log2n) Orderly repeatable
map Red and black trees Insert 、 Delete 、 lookup O(log2n) Orderly Do not repeat
multimap Red and black trees Insert 、 Delete 、 lookup O(log2n) Orderly repeatable
unordered_set Hashtable Insert 、 Delete 、 lookup O(1) The worst O(n) disorder Do not repeat
unordered_multiset Hashtable Insert 、 Delete 、 lookup O(1) The worst O(n) disorder repeatable
unordered_map Hashtable Insert 、 Delete 、 lookup O(1) The worst O(n) disorder Do not repeat
unordered_multimap Hashtable Insert 、 Delete 、 lookup O(1) The worst O(n) disorder repeatable

版权声明
本文为[D3qbz0a]所创,转载请带上原文链接,感谢

随机推荐