The bottom layer of each container such as list, vector, deque, set, map, etc.

Several containers and features commonly used in STL:
list: The bottom layer is a doubly linked list. The efficiency of inserting new elements before and after the current node is O(1). Of course, if orderly insertion is required, it will degenerate to O(n). Because it is necessary to traverse and compare the element value
vector: the bottom layer is a dynamic array, which encapsulates the common operations of the array and is convenient to use. The insertion performance is O(n) and the tail insertion is O(1);
deque: mainly compared with vector, from The performance of header insertion is better than vector;
set: the bottom layer is a red-black tree, which directly stores user data, and the stored data is required to be comparable. The insertion performance is log(n), and the balance adjustment rules of the tree will have a certain overhead ;
Map: The bottom layer is a red-black tree, and the stored data type is pair (key-value pairs). Compared with set, map has lower requirements for stored user data, and transfers the requirements to the key;
pair: usually The storage data type of map can only store two values. pair, born for map (pot cow, born for dreams, I don’t know where the advertisement is);
priority_queue: the bottom layer is a heap structure (large and small top heap), and the priority queue is a combination of queue structure and ordered storage to ensure the team The first element is the current extreme value;

Guess you like

Origin blog.csdn.net/qq_43360777/article/details/106326195