Introduction to STL common containers

1 Sequential container

1.1  and

deque: double-ended queue dobule-ended queue (bidirectional opening), equivalent to a dynamic array; the head and tail are inserted and deleted data quickly; the memory allocation of this container is segmented continuous, not all memory is continuous together

1.2 stack

stack: last in first out, there is only one opening, deque has two openings, deque is more powerful than stack, deque actually contains stack function

1.3 list 

Doubly linked list, no need to link the memory between each element; the search efficiency is not outstanding, inserting and deleting elements at any position is very fast

 

1.4 forward_list

forward_list is newly added in c ++ 11, one-way linked list (restricted list), but it saves memory, especially when there are many elements, the saved memory is very considerable

 

2 Associated container

2.1 set/map

set / map: Associated container; most of the internally implemented data structures are red and black trees; when we save data in this container, we do not need to specify the data location, this container will automatically arrange the elements you add according to an algorithm A location

map: There are two items for each element, it is a key / value (key / value); generally, the value is found by the key; (the search is particularly fast, the insertion speed may be slightly slower); the value by the key is particularly fast; Same, if you have to make the key the same, you have to use multimap

Set does not exist that there is no key-value pair; each element is a value; element value can not be repeated, if you want to repeat, then you can use multiset

2.2 unordered_set,unordered_multiset等unordered_map,unordered_multimap

Internally implemented bit hash table

Published 123 original articles · praised 31 · 90,000 views +

Guess you like

Origin blog.csdn.net/qq_40794602/article/details/102992913