STL = Standard Template Library,标准模板库。包含容器(Container)、迭代器(Iterator)、算法(algorithm)。
一、容器
Sequence containers(序列容器)
Sequence containers implement data structures which can be accessed sequentially.
(since C++11)
| static contiguous array (class template) |
dynamic contiguous array (class template) | |
double-ended queue (class template) | |
(since C++11)
| singly-linked list (class template) |
doubly-linked list (class template) |
Associative containers(关联容器)
Associative containers implement sorted data structures that can be quickly searched (O(log n) complexity).
collection of unique keys, sorted by keys (class template) | |
collection of key-value pairs, sorted by keys, keys are unique (class template) | |
collection of keys, sorted by keys (class template) | |
collection of key-value pairs, sorted by keys (class template) |
Unordered associative containers(未排序关联容器)
Associative containers implement unsorted (hashed) data structures that can be quickly searched (O(1) amortized,O(n) worst-case complexity).
(since C++11)
| collection of unique keys, hashed by keys (class template) |
(since C++11)
| collection of key-value pairs, hashed by keys, keys are unique (class template) |
(since C++11)
| collection of keys, hashed by keys (class template) |
(since C++11)
| collection of key-value pairs, hashed by keys (class template) |
Container adaptors(容器适配器)
Container adaptors provide a different interface for sequential containers.
adapts a container to provide stack (LIFO data structure) (class template) | |
adapts a container to provide queue (FIFO data structure) (class template) | |
adapts a container to provide priority queue (class template) |
Member map
This is a comparison chart with the different member functions present on each of the different containers:
Amortized complexity shown. Legend: O(1) constant < O(log n) logarithmic < O(n) linear; *=depends on container
Container adaptors:
Container Adaptors | |||||
---|---|---|---|---|---|
Headers | <stack> | <queue> | |||
Members | stack | queue | priority_queue | ||
constructor | * | constructor | constructor | constructor | |
capacity | size | O(1) | size | size | size |
empty | O(1) | empty | empty | empty | |
element access | front | O(1) | front | ||
back | O(1) | back | |||
top | O(1) | top | top | ||
modifiers | push | O(1) | push | push | push |
pop | O(1) | pop | pop | pop |