Cpp
priority_queue
- max heap by default
TODO Priority Queue
priority_queue<int, vector<int>, greater<int>> min_heap;
Templates
template <typename T>
class myArray {
};
Vectors
vector<int> vec(5, 1); // vec of size 5 with default value of 1
Queues
queue<int> q;
q.top();
q.push(1);
Maps
unordered_map<string, int> map;
map.count("elem"); // 1 if it's in the map and 0 otherwise
if (map.find("val") != map.end()) {
}
// or
if (map.count("val")) {
}
Sets
std::unordered_set set;
set.insert(1);
set.erase(1);
if (set.count("val")) {
}
Stacks
std::stack stack;
if (stack.empty()) {
}
Strings
std::isalnum(c);
std::tolower(c);
Finding a value in an array
.
Reversing stuff
std::reverse(str.begin(), str.end());
Compiling and running
Lambdas / functions as types
sort(arr.begin(), arr.end(), [](const int a, const int b) {
return a > b;
});
DP
int dp[10][20] = {0};