C ++ STL (Standard Template Library) learning to know

C ++ the STL (Standard Template Library) is a powerful C ++ template class provides generic template class and function, these template classes and functions may be implemented more popular and commonly used algorithms and data structures, such as vectors, linked lists, queues stack.

The core C ++ standard template library includes the following three components:

组件 描述
容器(Containers) 容器是用来管理某一类对象的集合。C++ 提供了各种不同类型的容器,比如 deque、list、vector、map 等。
算法(Algorithms) 算法作用于容器。它们提供了执行各种操作的方式,包括对容器内容执行初始化、排序、搜索和转换等操作。
迭代器(iterators) 迭代器用于遍历对象集合的元素。这些集合可能是容器,也可能是容器的子集。

These three components are presented with a wealth of predefined functions, help us deal with complex tasks in a simple way.

 

Containers (Containers)

Overall container can be divided into two categories:

Sequence containers Sequence containers, are clustered sequence, wherein each element has a fixed position - depending on the time and place of insertion, regardless of the value element, and
if you can additionally manner into a cluster of six elements, they the sort order and placed in the same order. SLT sequence containers provided: Vector, the deque, List

Associative containers Associative containers, has a cluster sequence, depending on the particular position of the element if the ranking criteria into six elements, their location on the element.
Correlation value and placed in containers provided .STL order independent: SET, multiset , map, multimp

 

 

 Comparative characteristics of STL containers with container behind the distribution is closely related to memory, from the figure can be clearly seen.
1, array, vector, deque memory is continuous, contiguous memory space must support random access, comprising the remaining features of the container is not. Wherein the array is a fixed length, vector, deque of variable length, vector only unidirectional expansion, deque expanded in both directions.
2, list, forward-list for the chain-type structure, which is inserted in, only partial adjustment is convenient when deleted. But only in order to traverse the chain in accordance with the order of traversal, does not find them quickly.
3, set, realization map behind the red-black tree , so has the inherent advantages of the find, but will generate linkage effects when this structure is inserted deleted, it is not suitable for frequent deletions, insertions. Wherein the respective multi version represents the content can be repeated.
----------------
Disclaimer: This article is the original article CSDN bloggers "Polaroid2007", and follow CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement. .
Original link: Classification and container contrast https://blog.csdn.net/LanerGaming/article/details/80768543
 

 Iterators (iterators)

With a collection, then how to traverse it? Iterator traversal is to provide a variety of methods: traversing forward, backward traversal, traversing from the middle, and so on, according to their needs to select the appropriate method.

Guess you like

Origin www.cnblogs.com/sengzhao666/p/11919053.html