#include<vector> => Library to includevector<int> v => Initialize a vector, Memory allocated is 0vector<int> v(n, m) => Initialize a vector of size 'n' with all values equal to 'm'vector<int> v1(v) => Initialize a vector by copying another vectorvector<int> v[n] => Initialize a vector of array elements of size 'n'vector<pair<int, int>> v => Initialize a vector containing a pairV.push_back(val) => Insert element at the endV.pop_back() => Returns the last element of the vector and removes itV.at(n) => Returns value at nth positionv[n] => Returns value at nth positionV.capacity() => Returns size of memory allocated, Total number of element that can be insertedV.size() => Returns number of element presentV.front() => Returns first element of the vectorV.back() => Returns last element of the vectorV.clear() => Size becomes 0 but not CapacityV.begin() => Returns an iterator pointing to the first element in the vectorV.end() => Returns an iterator pointing to the theoretical element that follows the last element in the vectorV.size() => Returns the number of elements in the vectorV.max_size() => Returns the maximum number of elements that the vector can holdV.capacity() => Returns the size of storage space currently allocated to the vector expressed as number of elementsV.resize(n) => Resizes the container so that it contains ‘n’ elementsV.empty() => Returns whether the container is emptyV.at(n) => Returns the value in that positionV.shrink_to_fit() => Reduces the capacity of the container to fit its size and destroys all elements beyond the capacityV.reference_operator[n] => Returns a reference to the element at position ‘n’ in the vectorV.assign() => It assigns new value to the vector elements by replacing old onesV.insert() => It inserts new elements before the element at the specified positionV.erase(n) => Removes the element present at position, n should be an iterator pointing to the positionV.erase(n, m) => Removes the elements in the range from start to end inclusive of the start and exclusive of the endsort(n, m, greater<int>()) => Sort the elements in descending order, third parameter is used to specify order in which elements are to be sortedsort(n, m, functionName) => We can also write our own comparator boolean function and pass it as a third parametersort(n, m) => Sorts the elements in ascending, Parameter n is starting and m is ending indexV.clear() => It is used to remove all the elements of the vector containeraccumulate(n, m, 0) => To get the sum of the vectorcount(n, m, o) => Returns count of the number of elements*max_element(n, m) => To get Max element of the vector, Returns iterator to the element*min_element(n, m) => To get Min element of the vector, Returns iterator to the elementpartial_sum(n, m, n) => To convert the vector into a prefix sum vector, Vector received by doing cumulative sumV.emplace() => It extends the container by inserting new element at positionV.emplace_back() => It insert a new element in vector container, the new element is added to the end of the vector for(auto i: v) {
cout << i << " ";
}
vector<int> :: iterator itr;
for(itr = V.begin(); itr != V.end(); ++itr) {
cout << *itr << endl;
}
vector<vector<int>> v => Initialize a 2D vectorvector<vector<int>> v = {{}, {}, {}}; => Initialize and Declarev[n][m] => Access the values for (auto row: v) {
for (auto i: row) {
cout << i << " ";
}
cout << endl;
}
for (vector<vector<int>>::rowItr = V.begin(); rowItr != V.end(); ++rowItr) {
for (vector<int>::iterator itr = rowItr->begin(); itr != rowItr->end(); ++itr) {
cout << *itr << " ";
}
cout << endl;
}