- vector, variable length array, the idea of doubling
size() returns the number of elements
empty() returns whether it is empty
clear() clears
front()/back()
push_back()/pop_back()
begin()/end()
rotate(a.begin(),a.begin()+k,a.end()) rotate array function
Supports comparison operations, in lexicographic order
- pair<int, int>
first, the first element
second, the second element
supports comparison operations, with first as the first keyword and second as the second keyword (lexicographic order)
- string, string
size()/length() returns the string length
empty()
clear()
substr(starting subscript, (substring length)) returns the substring
c_str() returns the starting address of the character array where the string is located
- queue, queue
size()
empty()
push() insert an element to the end of the queue
front() return the element at the head of the queue
back() return the element at the end of the queue
pop() pop up the element at the head of the queue
- priority_queue, priority queue, default is large root heap
size()
empty()
push() insert an element
top() return the top element of the heap
pop() pop the top element
of the heap defined as a small root heap: priority_queue<int, vector<int>, greater<int>> q;
- stack, stack
size()
empty()
push() insert an element to the top of the stack
top() return the top element of the stack
pop() pop the top element of the stack
- deque, double-ended queue
size()
empty()
clear()
front()/back()
push_back()/pop_back()
push_front()/pop_front()
begin()/end()
- set, map, multiset, multimap, based on balanced binary tree (red-black tree), dynamically maintain ordered sequence
size()
empty()
clear()
begin()/end()
++, -- returns the predecessor and successor, time complexity O(logn)
set/multiset
insert() Insert a number
find() Find a number
count() Return the number of a certain number
erase()
(1) The input is a number x, delete all x O(k + logn)
(2) Input An iterator, delete this iterator
lower_bound()/upper_bound()
lower_bound(x) Iterator that returns the smallest number greater than or equal to x
upper_bound(x) Iterator that returns the smallest number greater than x
map/multimap
insert() The inserted number is a pair
erase() and the input parameter is pair or iterator
find()
[] Note that multimap does not support this operation. The time complexity is O(logn)
lower_bound()/upper_bound()
unordered_set, unordered_map, unordered_multiset, unordered_multimap, the hash table
is similar to the above, the time complexity of adding, deleting, modifying and checking is O(1),
lower_bound()/upper_bound() is not supported, ++ of iterator, --
- bitset, pressure bit
bitset<10000> s;
~, &, |, ^
>>, <<
==, !=
count() returns how many 1's there are
any() determines whether there is at least one 1
none() determines whether all are 0
set() sets all bits to 1
set(k, v) sets the k-th bit to v
reset() sets all bits to 0
flip() is equivalent to ~
flip(k) inverts the k-th bit