Array

Some Functions

vec.back()
vec.front()

vec.capacity()
vec.size()
vec.reserve(n)

vec.push_back(x)
vec.pop_back()

vec.clear()
Removes all elements from the vector (which are destroyed), leaving the container with a size of 0.
To construct subarray: vector<int> sub(A.begin()+i, A.begin()+j)

Algorithms

binary_search(A.begin(), A.end(), 42)

lower_bound(A.begin(), A.end(), 42)

lower_bound(A.begin(), A.end(), 42)

fill(A.begin(), A.end(), 42)

swap(x, y)

reverse(A.begin(), A.end())

rotate(A.begin(), A.begin()+shift, A.end())
// 1 2 3 4 5 6 7 8 9 -> 4 5 6 7 8 9 1 2 3 if shift=3

sort(A.begin(), A.end())

Insert

std::vector::insert

single element (1)  
iterator insert (iterator position, const value_type& val);
fill (2)    
    void insert (iterator position, size_type n, const value_type& val);
range (3)   
template <class InputIterator>
    void insert (iterator position, InputIterator first, InputIterator last);

Return:
An iterator that points to the first of the newly inserted elements.

Erase

std::vector::erase

iterator erase (iterator position);
iterator erase (iterator first, iterator last);

An iterator pointing to the new location of the element that followed the last element erased by the function call. This is the container end if the operation erased the last element in the sequence.

results matching ""

    No results matching ""