c ++ STL vector preliminary study

/ * vector (vector): is a sequential container ,, dynamic arrays, arrays, and in fact almost, but it is superior to the array.
In general dynamic arrays can not expand, so when the program is running is not a waste of memory, is caused by cross-border.
The vector made up for this deficiency, it is equivalent to an array of features that can be assigned expansion,
its fast random access, insertions and deletions in the middle of a slow, but at the end of the fast insertion and deletion.
2. vector declaration and initialization
vector <int> vec; // declare a type int vector
vector <int> vec (5) ; // declare a vector of initial size of int 5
vector <int> vec (10, 1); // declare a size 10 and the initial value is a vector of a
vector <int> vec (tmp) ; // declaration and initialization vector vec vector tmp by
vector <int> tmp (vec.begin ( ), vec.begin () + 3); // vectors vec 0th to the second initialization value tmp
int ARR [. 5] = {. 1, 2, 3,. 4,. 5};  
vector <int> vec (ARR, ARR +. 5) ; // the array element arr for initializing vector vec
  @ DESCRIPTION: excluding of course arr [. 4] element at the end of the next element pointer refer to the end element,
 // and this is mainly to vec.end () pointer unity.
10 vector <int> vec (& arr [1], & arr [4]); // element within the scope of the arr [1] ~ arr [4 ] as initial values of vec
3. Common Operation
v1.push_back () // add the last data array
v1.pop_back () // remove the last data array
v1.front () // returns the first element (top element)
v1.begin () / / head pointer array to obtain, with acceptable iterator
v1.end () // get a pointer to an array of +1 last unit accepts an iterative
v1.clear () // remove all data from the container
v1.empty ( ) // determines whether the container is empty
v1.erase (pos) // delete data position pos
v1.erase (beg, end) // delete [beg, end) section data
v1.size () // back into the container the number of actual data
v1.insert (pos, data) // data inserted at pos

Guess you like

Origin www.cnblogs.com/QingyuYYYYY/p/11620849.html