Sequential Containers
元素在顺序容器中的顺序与其加入容器时的位置相对应。
Container Operations
vector<int> vec; |
定义和初始化容器
C c | 默认初始化 |
---|---|
C c1(c2) | |
C c1=c2 | |
C c{a,b,c,…} | |
C c={a,b,c,…} | |
C c(b,e) | 迭代器初始化,[b,e) |
C seq(n) | |
C seq(n,t) | n个元素,值为t |
Container Adaptors
容器适配器
stack
queue
priority_queue
template <class T, class Container = vector<T>, class Compare = less<typename Container::value_type> > class priority_queue; |
Compare:
comp(a,b),如果a应该出现在b前面,返回true,弹出的元素是根据strict weak ordering的最后一个元素
A binary predicate that takes two elements (of type T) as arguments and returns a
bool
.
The expressioncomp(a,b)
, where comp is an object of this type and a and b are elements in the container, shall returntrue
if a is considered to go before b in the strict weak ordering the function defines.
The priority_queue uses this function to maintain the elements sorted in a way that preserves heap properties (i.e., that the element popped is the last according to this strict weak ordering).
This can be a function pointer or a function object, and defaults toless<T>
, which returns the same as applying the less-than operator (a<b
).