Brush title wow

Vector

One-dimensional

vector<int> a(10, 1);
a.push_back(2);
a.size() ;
//删除 a.erase(itbgin,itend);

Two-dimensional

vector<vector<int> > v(3);
for(int i = 0;i < v.size(); ++i)
        for(int j = 0; j < 4; ++j)
            v[i].push_back(j);

rownum=v.size();
colnum=v[0].size();

vector deduplication

	set<int>s(vec.begin(), vec.end());
    vec.assign(s.begin(), s.end());

String

Reverse: reverse (str.begin (), str.end ());
sections: pre = strs.substr (0, j );
look for: strs.find (pre)
- Returning the location to find the first time
- can not be found a return string :: npos
inserted: str.insert (pos, inserStr)
initialization: string temp (n, '0 ');
delete: str.erase (remove (str.begin () , str.end (), 'a . '), str.end ()) ; // all equal between in the container, remove [begin, end)' a 'value of the
split function to achieve

void split(string &s, vector<string> &list1)
{
	istringstream tmp_string(s);
	string ss;
	while (getline(tmp_string, ss, ','))
	{
		list1.push_back(ss);
	}

}

stack

push() pop() top()

queue

push() pop() front() back()

tree

Standard definition of a binary tree

struct TreeNode {
 int val;
 TreeNode *left;
 TreeNode *right;
 TreeNode(int x) : val(x), left(NULL), right(NULL) {}
};

New node: TreeNode * roots = new TreeNode (val)

String

Defined char * str;
end of the string '\ 0'

Stringstream

int to string conversion

Stringsteam ss;
string st;
int t;

ss.clear();
ss<<st;
ss>>t;

to_string
stoi stol stoll

Binary conversion
ss << oct << a; // 10 decimal turn octal read feedstream
ss << hex << a; // 10 hex to hex turn read feedstream

Binary processing

bitset <digits> a (string or int pending numeral)
digits 1: a.count ()

Determine whether the same double

bool equal(double num1,double num2)

{

if((num1-num2>-0.00000001)&&(num1-num2)<0.00000001)
    return true;
    else return false;

}
Published 35 original articles · won praise 2 · Views 1432

Guess you like

Origin blog.csdn.net/qq_30776035/article/details/103054615