push_front vector c++ code example
Example 1: inserting at start in vector c++
vector_name.insert(vector_name.begin(), element_to_be_inserted);
vector_name.insert(vector_name.begin()+(x-1), element_to_be_inserted);
vector_name.push_back(element_to_be_inserted);
Example 2: c++ vector
#include <vector>
int main() {
std::vector<int> v;
v.push_back(10);
v.push_back(20);
v.pop_back();
v.push_back(30);
auto it = v.begin();
int x = *it;
++it;
int y = *it;
++it;
bool is_end = it == v.end();
return 0;
}
Example 3: insert at position in vector c++
v.insert(v.begin() + i, v2[i])
Example 4: vector push front insert()
auto it = vec.insert(vec.begin(), 3);