Vector
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
| vector<int> a(n, x); a.size();a.empty(); a.clear(); a.front();a.back(); a.push_back();a.pop_back(); a.begin();a.end(); a.erase(a.begin(), a.begin()+n); a.resize(m);
vector<int> a(10, -3); vector<int> b(9, 2); if(a < b){ cout << "a < b"; }
|
Pair
1 2 3 4
| pair<int, int> p; p = {1, 2}; p.first;p.second;
|
String
1 2 3 4 5 6 7 8 9 10 11 12 13
| string str; str.erase(i, j); str.replace(i, n, s);
#include <string> tolower(str[i]); toupper(str[i]);
str.find(s, st); str.substr(i, n); str.insert(str.begin(), x); str.clear(); printf("%s\n%s", a, a.c_str());
|
Queue
1 2 3 4
| queue<int> q; q.size();q.empty(); q.front();q.back(); q.push();q.pop();
|
Priority_Queue
1 2 3 4 5 6 7 8 9
| priority_queue<int> heap; heap.push(x); heap.top(); heap.pop();
|
Stack
1 2 3 4
| stack<int> q; q.size();q.empty(); q.push(x);q.pop(); q.top();
|
Deque
1 2 3 4 5 6 7
| deque<int> q; q.size();q.empty(); q.front();q.back(); q.push_back(x);q.pop_back(); q.push_front(x);q.pop_front(); q.begin();q.end(); q.clear();
|
set, map, multiset, multimap基于平衡二叉树(红黑树),插入删除都是O(logn)
Set/Multiset
1 2 3 4 5 6 7 8 9 10
| size();empty(); clear(); insert(x);find(x); count(x); erase();
lower_bound(x); upper_bound(x);
|
Map/Multimap
1 2 3 4 5 6 7 8 9
| size();empty(); clear(); insert(x);find(x); count(x); erase();
lower_bound(x); upper_bound(x);
|
unordered_set, unordered_map, unordered_multiset, unordered_multimap基于哈希表,插入删除都是O(1),不支持lower_bound()和upper_bound()
Bitset
1 2 3 4 5 6 7 8 9
| bitset<10000> s; s[1]; s.count(); s.any(); s.none(); s.set(); s.reset(); s.set(k, v);
|