1 Basic operations
(1) Header file #include
(2) Create vector object, vector
(3) Insert numbers at the end: vec.push_back(a);
(4) Use subscripts to access elements, cout< (5) Use iterator to access elements. 3 Algorithm (1) Use reverse to flip elements: the header file is required #include reverse(vec.begin(),vec.end()); Element flipping (in vector, if two iterators are required in a function, generally does not include the latter one.) (2) Use sort to sort: the header file #include sort(vec .begin(),vec.end()); (The default is to sort in ascending order, that is, from small to large). You can compare in descending order by rewriting the sorting comparison function, as follows: Define the sorting comparison function: bool Comp(const int &a,const int &b) For more related content, please pay attention to the php Chinese website (www.php. cn)!
{
return
a>b;
}
When calling: sort(vec.begin(),vec.end(),Comp), this will sort in descending order