C++ Guides
C++ Guides
C++ Guides
#include<climits>
INT_MAX = ~(1 << 31) // for 64bit machine
INT_MIN = 1 << 31 // for 64bit machine
UINT_MAX = (uint)(~0) // 32 bit all equal 1
LONG_MAX
LONG_MIN
ULONG_MAX
str.append("abc");
str.append(1, 'a'); // append character
size_t found = str.find("ab"); // return pos where "ab" first occur
in str. NOTE: the return pos is size_t !!!
if (found!=string::npos) cout << "found"; //
#include <algorithm>
sort(v.begin(), v.end()); // sort vector and from min to max by default
struct cmp{
bool operator() (int x, int y){
return x > y; // descending order
}
} cmpObj;
sort(v.begin(), v.end(), cmpObj); // sort with self-defined comparator
Map.erase("one"); // delete
Map.empty();
Map.size();
unordered_set<int> Set;
Set.insert(val);
Set.erase(val);
Set.erase(iterator);
Set.size();
Set.empty();
if(Set.find(1) != Set.end()) cout << "found" << endl; // find val equivalent to
set.contains(val)
for(iter = Set.begin(); iter != Set.end(); ++iter) // traverse
cout << *iter <<endl;
struct cmp{
bool operator()(Node* a, Node* b){
return (a->val) < (b->val);
}
};
set<Node*, cmp> s; //intialize ordered set
with comparator
struct cmp{
bool operator()(Node* a, Node* b){
return a -> x > b -> x; // build min heap
}
};
#include<deque>
deque<int> dq (2,0);
dq.push_back(1);
dq.push_front(-1);
cout << dq[0] << endl;
Example:
for (int i=1; i<10; ++i) vec.push_back(i); // 1 2 3 4 5 6 7 8 9
rotate(vec.begin(),vec.begin()+3,vec.end());// 4 5 6 7 8 9 1 2 3
class TreeNode{
public:
int val;
TreeNode *left;
TreeNode *right;
TreeNode(int val){
this->val = val;
this->left = NULL;
this->right = NULL;
}
};
class TrieNode{
public:
char ch;
bool isWord;
TrieNode* next[26];
TrieNode(char ch){
this->ch = ch;
this->isWord = false;
memset(next, 0, sizeof(next));
}
};
class Node{
public:
int x;
int y;
Node(int x, int y){
this->x;
this->y;
}
friend operator < (Node& a, Node& b){
return this.x - that.x;
}
void print(){
cout<< this->x << this->y <<endl;
}
};
/*********************** pointer **********************/