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

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.

主站蜘蛛池模板: 长海县| 萨迦县| 紫金县| 五常市| 北辰区| 陕西省| 信宜市| 嵊州市| 榆中县| 阳新县| 旬阳县| 水城县| 和林格尔县| 镇原县| 富锦市| 博罗县| 亚东县| 华亭县| 抚宁县| 邯郸县| 沙河市| 河源市| 东阿县| 灵山县| 凯里市| 金堂县| 金湖县| 夏津县| 商丘市| 西华县| 南乐县| 闵行区| 绥滨县| 龙泉市| 孙吴县| 镇原县| 保康县| 富锦市| 新平| 六枝特区| 岳阳市|