-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathC++ grammar
18 lines (13 loc) · 852 Bytes
/
C++ grammar
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
1. vector
vector<int> a(n): make a vector's size to be n and initialize it with 0
use push_back to add new element to the vector. never use [] to add value to a vector
vector<vector<int>> visited(row,vector<int>(col)); how to initialize a 2-D vector
vector<ptr*> this needs to be thought very carefully, as if ptr* changes, the whole thing in vector will change, so better use "new" every time if you want different ptr values.
2. string
string s1; create an empty string (with 1 '\0' at the end)
3. new
TreeNode* rootPtr = new TreeNode(val); it's that easy
4. round
round(a/2) means no sense if a is an integer, better use round(a/2.0)
5. sort
sort(class.begin(),class.end(),compare); compare should be a static bool member function of the class, if you want a < b, just return a < b