官术网_书友最值得收藏!

Associative containers

Associative containers store data in a sorted fashion, unlike the sequence containers. Hence, the order in which the data is inserted will not be retained by the associative containers. Associative containers are highly efficient in searching a value with O( log n ) runtime complexity. Every time a new value gets added to the container, the container will reorder the values stored internally if required.

The STL supports the following types of associative containers:

  • Set
  • Map
  • Multiset 
  • Multimap
  • Unordered set
  • Unordered multiset
  • Unordered map
  • Unordered multimap

Associative containers organize the data as key-value pairs. The data will be sorted based on the key for random and faster access. Associative containers come in two flavors:

  • Ordered 
  • Unordered

The following associative containers come under ordered containers, as they are ordered/sorted in a particular fashion. Ordered associative containers generally use some form of Binary Search Tree (BST); usually, a red-black tree is used to store the data:

  • Set
  • Map
  • Multiset
  • Multimap

The following associative containers come under unordered containers, as they are not ordered in any particular fashion and they use hash tables:

  • Unordered Set
  • Unordered Map
  • Unordered Multiset
  • Unordered Multimap

Let's understand the previously mentioned containers with examples in the following subsections.

主站蜘蛛池模板: 五家渠市| 轮台县| 富裕县| 永兴县| 定安县| 常山县| 海淀区| 中宁县| 扶绥县| 北安市| 读书| 从化市| 万全县| 高唐县| 即墨市| 湟中县| 清水河县| 盐城市| 岑溪市| 石柱| 德江县| 额济纳旗| 文登市| 毕节市| 朝阳县| 南漳县| 肥西县| 高要市| 桃江县| 改则县| 江华| 玉田县| 合肥市| 淮南市| 大庆市| 舒城县| 虎林市| 高平市| 迁安市| 永德县| 双桥区|