Talking about the difference between sequential container and associative container

Sequence container and associative container diagram:

Insert picture description here

 

1. The difference between sequential containers and associative containers:

①The sequence container has only real value val.

② An element of an associative container contains two parts: key-value pairs (key-value), namely <k value (key value)|real value>.

③Sequential container does not involve sorting, and the associative container is automatically sorted.

④The essential difference: sequential containers store and access elements sequentially through their positions in the container, while associative containers store and read elements through keys.

2.The difference between ordered and unordered containers in associative containers:

① Ordered container (the underlying structure is: red-black tree)

(1)map;//key不允许重复
(2)multimap;//key允许重复
(3)set;//Key=val;key不允许重复
(4)multiset//Key=val;key允许重复

It is the standard library in stl.

②Disordered container (the underlying structure is: hash table)

(1)unorder_map; 
(2)unorder_multimap; 
(3)unorder_set; 
(4)unorder_multiset

 It is a container in the boost library. At present, the boost library is a quasi-standard library. You need to add a library when you use it.

Guess you like

Origin blog.csdn.net/weixin_45590473/article/details/108032281